tags:

views:

28

answers:

1

I'm using the HTML::TokeParser to parse an HTML file and get data within div tags. My HTML is as follows:

<div class='t_and_h f_t' id='t_f_i'>
  <div class='icon'>
    <img alt="icon" src=""/>
  </div>
  <div class='t'>
    12:31 PM
  </div>
  <div class='h'>
    <a>Residue 4</a>
  </div>
  <div class='f_t'>
    TRUE
  </div>
</div>

My code is as follows:

while ( $tag = $stream->get_tag('div') ) 
{
    if($tag->[1]{class} eq 't')
    {   
        $time = $stream->get_trimmed_text('</div>');
        print "$time \n";
    }
}

But the ouput prints all the fields, i.e

12:31PM Residue 4 TRUE

What am I doing wrong?

A: 

</div> is the outer closing tag. Just leave it away to stay at the current stream position, thus:

my $time = $stream->get_trimmed_text; 
# 12:31 PM
daxim