How to download Web Pages in Java?

B

Bari Bai

As the title, which class in Java could be used to download web pages from a
specific URL?

Any example code/usage would be greatly appreciated.

I can download the pages using FTP programs; but I want to download the web
pages in Java program since I need to process the dynamic information in the
files.

Thanks!

Jim
 
C

Christophe Vanfleteren

Bari said:
As the title, which class in Java could be used to download web pages from
a specific URL?

Any example code/usage would be greatly appreciated.

I can download the pages using FTP programs; but I want to download the
web pages in Java program since I need to process the dynamic information
in the files.

Thanks!

Jim
Check out http://jakarta.apache.org/commons/httpclient/.
 
V

VisionSet

Bari Bai said:
As the title, which class in Java could be used to download web pages from a
specific URL?

Any example code/usage would be greatly appreciated.

I can download the pages using FTP programs; but I want to download the web
pages in Java program since I need to process the dynamic information in the
files.

StringBuffer getSource() throws IOException {
InputStream is;
URLConnection uc;
URL url = new URL("http://www.foo.bar");
uc = url.openConnection();
is = url.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer source = new StringBuffer();
String line = null;
while((line = in.readLine()) != null) {
source.append(line);
}
return source;
}

Something like that, using java.net & java.io packages
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top