1.11M Members

Java code to read the text from a webpage!!

 
0
 

I want to know how can we read the texts that are in a webpage and store it in a file in our local disk. i want to read the text line by line and store it in the text file in my local disk. can anyone help me???

 
0
 

ok!!! i m new to java.. can i do this using net beans? i created a sample html page with some text in that. shud i write the codin in a java class or servlet? what package to import?

 
0
 

You can write it in any editor that you please. Read the links and check the API docs for those classes that you do not know.

 
0
 

which links??? the one u gave with the first reply??

 
0
 

which links??? the one u gave with the first reply??

 
0
 
try {
        // Create a URL for the desired page
        URL url = new URL("http://localhost:8084/WebAppliccation2/sample.html");

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {

}
in.close();

wat shud i write in the while loop??

 
0
 
try {
        // Create a URL for the desired page
        URL url = new URL("http://localhost:8084/WebAppliccation2/sample.html");

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {

}
in.close();

wat shud i write in the while loop??

 
0
 

please suggest me some books for reference

 
1
 

I already provided links above that cover the major steps involved. If you need more general links on Java, look through the "Read Me: Starting Java" thread that is stickied at the top of the forum.

 
0
 

check web-harvest. very useful for scrapping web pages

 
0
 

Hi Guys,
I have one doubt in above discussion,If we do like which you discussed above,We can get webpage source code only,If we want text means content ,then what we do guys.Any suggestion?

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article