Results 1 to 4 of 4
  1. #1
    Omarero is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default [SOLVED] retrieve the html code of any web page

    how can i retrieve the html code of any web page in java; for example i want to retrieve the html code of bbc.com in a string

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    11

    Default

    ...from java.net and java.io

    Java Code:
    HttpURLConnection http = new HttpURLConnection(<your url goes here>);
    
    http.connect();
    
    InputStream in = http.getInputStream();
    
    LineNumberReader reader = new LineNumberReader(in);
    
    
    StringBuffer buf = new StringBuffer();
    String thisLine = reader.readLine();
    
    while(thisLine != null) {
      buf.append(thisLine+"\n");
      thisLine = reader.readLine();
    }
    
    System.out.println(buf.toString());
    ...something liek this should work.

  3. #3
    Omarero is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default

    thanks so much...

  4. #4
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    11

    Default

    Omarero Please go to the top of the page and click Thread Tools, and then in the drop-down menu click Mark This Thread As Solved, so everyone knows your problem is solved and will not waste time looking. Thanks.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

Similar Threads

  1. read html code of web page
    By asheeshiit in forum Advanced Java
    Replies: 9
    Last Post: 01-07-2014, 09:31 PM
  2. to retrieve multiple values from html page through jsp
    By raghu9198 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 02-17-2009, 02:43 PM
  3. redirect to html page
    By simo_mon in forum Java Servlet
    Replies: 3
    Last Post: 02-12-2009, 05:18 PM
  4. to retrieve the webcontent from another page source
    By rameshsathasivam in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-25-2008, 08:41 AM
  5. HTML page
    By bbq in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •