1,105,399 Community Members

Java code to read the text from a webpage!!

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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???

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
0
 

Ok!! You just need to open an input stream from the URL, parse that for what you want, and write it to a text file!!

!!!!!

(All those exclamation points just look silly, don't they?... )

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
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.

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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??

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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??

Member Avatar
bkvijay
Newbie Poster
7 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

please suggest me some books for reference

Member Avatar
Ezzaral
Posting Sage
7,431 posts since May 2007
Reputation Points: 2,714 [?]
Q&As Helped to Solve: 953 [?]
Skill Endorsements: 31 [?]
Moderator
Featured
 
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.

Member Avatar
gcameo
Newbie Poster
6 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

check web-harvest. very useful for scrapping web pages

Member Avatar
muthu_tek
Newbie Poster
4 posts since Apr 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article