Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Is the span tag supported by HTML:Treebuilder

by ChilliHead (Monk)
on Jan 22, 2001 at 14:27 UTC ( [id://53462]=perlquestion: print w/replies, xml ) Need Help??

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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://53462]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found