Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Get HTML Source

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am trying to get the HTML source for say...google page.
The following is my code. But I get "openConnection() failed".
So, it is not getting connected. Any input will be appreciated.

Or if you can think of a better way of doing this. May be getting a handle using the DOM ( W3C etc) please let me know.


import java.net.*;
import java.io.*;

public class URLReader {
public static void main(String[] args) throws Exception {
try {
URL google = new URL("http://www.google.com/");

URLConnection gl = google.openConnection();

BufferedReader in = new BufferedReader(
new InputStreamReader(
gl.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();


// yahooConnection.connect();
System.out.println("OK");

} catch (MalformedURLException e) { // new URL() failed
System.out.println("new URL() failed");

} catch (IOException e) { // openConnection() failed
System.out.println("openConnection() failed");

}
}

}

Thanks.
 
Marshal
Posts: 76825
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't start a 2nd thread on the same subject.
 
Marshal
Posts: 27450
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
(Actually the first post was closed, so starting a new post was necessary.)

An Raj, you would get better information if you printed the stack trace, like this:
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Paul Clapham:
(Actually the first post was closed, so starting a new post was necessary.)



No, it was moved. Closing this dupe.
 
    Bookmark Topic Watch Topic
  • New Topic