Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read text content not source code from webpage in java ?

 
Marimuthu Udayakumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guyz..
How to read text content not source code from webpage using java ?

Thanks,
http://teknoturfian.blogspot.com
 
Venkateswara Rao Desu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java.net package we have URLConnection class is there. we can use that to connect to some URL and request and get response from that.
 
Marimuthu Udayakumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venkateswara ,
Thanks for your reply,
I tried this,


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;


public class URLExp {

public static void main(String[] args) {
try {
URL google = new URL("http://www.google.com/");
URLConnection yc = google.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc
.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);

}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}


BUT...
what happend i can get the source code of the webpage ,I need text based real content.So what i do?...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15440
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marimuthu Udayakumar wrote:BUT...
what happend i can get the source code of the webpage ,I need text based real content.So what i do?...

You'd have to parse the HTML in your program and get the text out of it yourself.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And next time, please http://faq.javaranch.com/java/UseCodeTags
 
Marimuthu Udayakumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jesper Young ,
Thanks for your query,I made it.

Hi Rob Prime,
Thanks for your suggesstion that code Tag, I used that Tag too here...

I used NekoHTML parser ..




I used jar files named nekohtml.jar and xercesImpl.jar for parser ,
I am not able to attach those jarfiles here.just you can download from web,
If you dont get it just mail me to teknoturfian@gmail.com
I will send it to you..
Thanks guys...Have a good day...
http://www.wix.com/muthu_tek/Marimuthu-at-Teknoturf
http://teknoturfian.blogspot.com

" I aim to bring Passion and Quality to every relationship"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic