Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by Uggles (Novice)
on Jul 10, 2013 at 17:35 UTC ( #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?

Comment on HTML::TreeBuilder - Multiple instances of text in the same tag
Select or Download Code
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
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? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-07-08 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls