Hi All,

I am trying to use HTML::TreeBuilder to parse some HTML data I have retrieved from the web. Specifily, I would like to extract the sunrise/sunset data from the web page. Below is what I have tried. The attribute I am looking for is everything between the pre tags, However I am afraid I do not understand what is being displayed when I print the all_attr method :(

Can anyone shead some light on this?

Thanks

Ron Hill

use strict; use warnings; use HTML::TreeBuilder; my $data = do { local $/; <DATA> }; my $tree = HTML::TreeBuilder->new_from_content($data); print $tree->all_attr(); __DATA__ <html> <head><title>Sun and Moon Data for One Day</title></head> <body> <br> <h4>U.S. Naval Observatory<br>Astronomical Applications Department</h4 +> <br> <h3>Sun and Moon Data for One Day</h3> <p>The following information is provided for Adelaide Australia (longitude E138.6, latitude S34.9): </p> <pre> Saturday 21 June 2003 Universal Time + 9h <strong>SUN</strong> Begin civil twilight 06:25 Sunrise 06:53 Sun transit 11:47 Sunset 16:41 End civil twilight 17:10 <strong>MOON</strong> Moonrise 22:45 on preceding day Moon transit 05:24 Moonset 11:53 Moonrise 23:43 Moonset 12:19 on following day </pre> <p>Last quarter Moon on 21 June 2003 at 23:45 (Universal Time + 9h). </p> <br> <br> <br> </body> </html>

Edit by tye, replace PRE with P tags


In reply to Parsing HTML using TreeBuilder by monsterzero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.