Here is an HTML::Parser API2 example that plonks all the stuff between text12 divs into an array - one element per div. You can easily modify it to drop tags you don't want but retain the list items.

use HTML::Parser; { package MyParser; use base 'HTML::Parser'; sub start { my($self, $tagname, $attr, $attrseq, $origtext) = @_; if ( $tagname eq 'div' and $attr->{class} eq 'text12' ) { push @{$self->{text12}}, ''; # start a new text 12 collec +tion $self->{in_text12} = 1; } else { $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } } sub end { my($self, $tagname, $origtext) = @_; $self->{in_text12} = 0 if $tagname = 'div'; $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } sub text { my($self, $origtext, $is_cdata) = @_; $self->{text12}->[-1] .= $origtext if $self->{in_text12}; } } my $p = MyParser->new; $p->parse_file(*DATA); print "Got: $_\n\n" for @{$p->{text12}}; __DATA__ <div class="text12">This text I don't need.</div> <div class="text12">This long test that is at least 201 characters in +length is what I want to parse. <br><br> Here is a list that I want to retrieve in this "div" tag.<br> List:<br> <li>item 1 <li>item 2 <li>item 4 </div>

cheers

tachyon


In reply to Re: HTML TokeParser - help with using get_text, get_trimmed_text by tachyon
in thread HTML TokeParser - help with using get_text, get_trimmed_text 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.