ChilliHead has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the traverse function in HTML::Treebuilder and it does not seem to recognise the span tag. My code is:
$html=$response->content; $treeparse=HTML::TreeBuilder->new; $treeparse->parse($html); $treeparse->traverse(\&treewalker); $treeparse->delete(); sub treewalker { my ($node, $start, $depth) = @_; if (ref $node) { my $tag = $node->tag; if ($tag eq "span") { .... } } }

it never executes the code with the if block even though there are span elements in the html I am parsing.

Replies are listed 'Best First'.
Re: Is the span tag supported by HTML:Treebuilder
by cianoz (Friar) on Jan 22, 2001 at 17:32 UTC
    you should add
    return HTML::Element::OK;
    at the end of the callback subroutine to keep traversing the tree, your code stops at the first tag
      I was already returning a value of 1 to make it loop through the tree but that was one of the lines I cut for brevity. I changed it to return HTML::Element::OK but it still does not work. It will pick out all the other tags that I've tried (such as div, a, b)

      CH
        it works fine for me, with SPAN and a with few other tags i tested, did you tried with other pages? it could be due to errors in the html syntax...