You just need to maintain state. I use HTML::Parser directly. There are two flags. One flip flops as we enter and leave a text12 chunk. The other counts text12 chunks. You could just as easily trigger on the <span id='fulldescription'> tag.

use HTML::Parser (); my $CHUNK = 2; # get Nth instance of text12 $p = HTML::Parser->new( api_version => 3, start_h => [ \&start, "self, tagname, attr" ] +, end_h => [ \&end, "self, tagname" ], text_h => [ \&text, "self, dtext" ] ); $p->parse_file(*DATA); sub start{ my ( $self, $tagname, $attr ) = @_; if ( $tagname eq 'div' and $attr->{class} eq 'text12' ) { $self->{text12}++; $self->{text12_item}++; } } sub end{ my ( $self, $tagname ) = @_; $self->{text12} = 0 if $tagname eq 'div'; } sub text{ my ( $self, $text ) = @_; print $text if $self->{text12} and $self->{text12_item} == $CHUNK; } __DATA__ <div class="text12"> Chunk 1 </div> <div class="text12"> Chunk 2 </div> <div class="text12"> Chunk 3 </div>

cheers

tachyon


In reply to Re: Parsing this HTML description by tachyon
in thread Parsing this HTML description by tanger

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.