Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

HTML::TreeBuilder - Multiple instances of text in the same tag

by Uggles (Novice)
on Jul 10, 2013 at 17:35 UTC ( [id://1043511]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to use TreeBuilder to get all of the strings in a certain tag of an HTML document into an array. I use find('mytag') which works fine to get all of the elements, but if I just print the array created from that then it prints HTML::Element hashes instead of the strings. That makes sense considering HTML::Element has the command "as_text". When I try to use "as_text" in the following way:

my @parsed = $element -> find('tag'); -> as_text(); print @parsed;

then it will only print the first instance of text within the desired tag instead of all of them. If I try and use "as_text" on @parsed in the following way:

my @parsed = $element -> find('b'); @parsed -> as_text(); print @parsed;

then I get a "Can't call method 'as_text' without package..." error. Is there a specific syntax for doing this that I just am not getting?

Replies are listed 'Best First'.
Re: HTML::TreeBuilder - Multiple instances of text in the same tag (perlintro)
by Anonymous Monk on Jul 10, 2013 at 23:48 UTC

    Is there a specific syntax for doing this that I just am not getting?

    Yes, read perlintro , esp arrays and foreach

Log In?
Username:
Password:

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

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

    No recent polls found