Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Try running this:

#!usr/bin/perl #simpleparse.pl use strict; use warnings; use HTML::SimpleParse; use Data::Dumper; my $html = <<'END'; <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id01">Completed 3:46 pm, 06 Dec, 2012< +/a></span> </div> <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id02">Completed 4:00 pm, 06 Dec, 2012< +/a></span> </div> END my $p=HTML::SimpleParse->new($html); print Dumper($p);

And see what the data structure from HTML::SimpleParse looks like. It flattens everything out so that it removes all the structure that helps you figure out what you want. You could probably cook up some combination of conditionals to sort out what shows up in what order to get the urls you want, but a fancier module will make your life easier, at the expense of having to read more of the manual.

Here's a solution using HTML::TreeBuilder (which uses HTML::Element for a lot of the interesting stuff)
#!usr/bin/perl #simpleparse.pl use strict; use warnings; use HTML::TreeBuilder; use Data::Dumper; my $html = <<'END'; <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id01">Completed 3:46 pm, 06 Dec, 2012< +/a></span> </div> <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id02">Completed 4:00 pm, 06 Dec, 2012< +/a></span> </div> <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id03">Not Completed 3:46 pm, 06 Dec, 2 +012</a></span> </div> <div class="views-field views-field-title"> <span class="fiel +d-content"><a href="/MAKER/gen/id04">Something done 4:00 pm, 06 Dec, +2012</a></span> </div> END my $p=HTML::TreeBuilder->new_from_content($html); my @urls=$p->find('_tag'=>'a'); foreach (@urls){ if ($_->as_text=~/^Completed/){ print $_->attr('href')."\n"; } } #print Dumper($p);

If you want to see how HTML::TreeBuilder parses your HTML into a structure, uncomment the last line with print Dumper($p). Compare that to what HTML::Simple does when it parses. It's a lot more complicated, but TreeBuilder and Element have a lot of methods to make that all mostly transparent.


In reply to Re: HTML::SimpleParse to parse HTML by bitingduck
in thread HTML::SimpleParse to parse HTML by techie411

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2014-07-30 05:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (229 votes), past polls