Results 1 to 3 of 3
  1. #1
    binhdinh0708 is offline Member
    Join Date
    Apr 2011
    Posts
    4
    Rep Power
    0

    Post Reading sourcode from a webpage

    I want to read source code from a webpage using url connection
    Here is my code:
    Java Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    import java.io.*;
     
    public class GetHTML {
       
        public static void main(String[] args) throws Exception
        {    
            URL hcm24h = new URL("http://hcm.24h.com.vn/");
            URLConnection yc = hcm24h.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
            in.close();
    }
    but what i received did not match with code from view page source from browser
    This is code from browser
    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head> 
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<title>Tin tuc 24h | tin nhanh bong da | the thao | thoi trang, giai tri vn | bao online</title>
    and this i code that i received.

    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content="width=device-width, height=device-height" name="viewport" />
    <title>Trang chủ 24h mobile</title>
    pls tell me why I have differences of them.
    and the way to fix it.

  2. #2
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Reading sourcode from a webpage

    Maybe you can use raw HTTP code
    or
    You can use Internet Explorer to get source code by using java
    I can send you a library that help you to manage Internet Explorer by that way you can manipulate internet explorer properties.
    You can get source like you always do with mouse

  3. #3
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Reading sourcode from a webpage

    Sory I forgot to tell the library name :>>> jiffie

Similar Threads

  1. loading webpage
    By juhiswt in forum New To Java
    Replies: 0
    Last Post: 03-17-2011, 07:37 PM
  2. [HELP] How to run this applet in webpage? [HELP]
    By velianko1 in forum Java Applets
    Replies: 4
    Last Post: 12-16-2010, 06:09 PM
  3. Getting content from a webpage--help!
    By danilson in forum Advanced Java
    Replies: 4
    Last Post: 12-01-2010, 03:19 PM
  4. Cannot Get gif to show on webpage
    By ShinTec in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-26-2010, 02:36 PM
  5. save a webpage.....?
    By 05bit044 in forum Networking
    Replies: 1
    Last Post: 08-04-2008, 05:49 PM

Posting Permissions

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