Results 1 to 10 of 10
  1. #1
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default Read HTML info from a web page

    Hi, I've managed to read and output to console some HTML from a web page, but it leaves out some of the info from the tags.

    Example:

    Rainfall for Feb, 12 2009 : 30mm

    The console output is:

    <div class="rain" style="width:110px;"></div>

    Note there is nothing in the div tag, but when I view the page source in a browser, the info is there.

    Is there any reason why the console would leave this information out?

    Cheers.

  2. #2
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    try posting your code where you read and write the file....so we can see better

  3. #3
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    I found the code in this forum but I can't post the link cause I'm under 20 posts:

    Java Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    
    
    public class URLExp {
    
    	public static void main(String[] args) {
    		try {
    			URL google = new URL("[COLOR="Red"]<PASTE LINK TO GOOGLE HERE>[/COLOR]");
    			URLConnection yc = google.openConnection();
    			BufferedReader in = new BufferedReader(new InputStreamReader(yc
    					.getInputStream()));
    			String inputLine;
    			while ((inputLine = in.readLine()) != null) {
    				System.out.println(inputLine);
    
    			}
    			in.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    }

  4. #4
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    post the link without the initial cPanel®

  5. #5
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    post the link without the initial http : // www

  6. #6
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    w w w.java-forums.org/java-tips/3293-how-read-web-page-through-java-program.html

  7. #7
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    i didn't think that link hehe
    i thought of the link of your example....so i can see if with this code you get what you wrote in the first post....and try to figure out why hehe

  8. #8
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    No probs, here it is:

    nutritiondata.com/facts/fruits-and-fruit-juices/2064/2

    Look in the HTML code for:

    <span id="NUTRIENT_0">48.6</span>

    For some reason, the java console leaves out the "48.6" but prints the rest.

  9. #9
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    i looked at that link's source page with chrome....
    and there wasn't the line

    <span id="NUTRIENT_0">48.6</span>

    but only

    <span id="NUTRIENT_0"></span>

    so it's correct that java gets you without the number.
    probably this numbers are calculated and inserted via javascript (as you can see by searching for javascript scripts in the page)

    maybe your browser gets you to view the source page with already executed javascript so it gets you the numbers also....

    but if you don't execute the javascript inside, by looking only to the html that span tags don't have values so java is correct

    hope it helped ;)

  10. #10
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    Ahh.. ok. That makes sense. So is there a way to execute the page like a browser would, and then read the data? Similar to how Firefox's Web Developer Tool works..

Similar Threads

  1. read html code of web page
    By asheeshiit in forum Advanced Java
    Replies: 9
    Last Post: 01-07-2014, 10:31 PM
  2. Replies: 5
    Last Post: 07-30-2008, 10:30 AM
  3. How to read a Web Page through java program
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-04-2008, 03:37 PM
  4. How to read a Web Page through java program
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:31 PM
  5. HTML page
    By bbq in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 04: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
  •