Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to use regex in Tree->look_down

by corpx (Acolyte)
on Oct 24, 2009 at 07:48 UTC ( #803011=perlquestion: print w/ replies, xml ) Need Help??
corpx has asked for the wisdom of the Perl Monks concerning the following question:

I need to look_down a tree and find all items which has style attributes of 128px;width:160px; (there might be more style attributes for items, but this is all I'm interested in) Is there any way to use regex to filter this? Currently I have @rows = $tree->look_down('style' => /128px\;width:160px\;/ ); but that doesnt even compile :/ Any ideas?

Comment on How to use regex in Tree->look_down
Download Code
Replies are listed 'Best First'.
Re: How to use regex in Tree->look_down
by GrandFather (Sage) on Oct 24, 2009 at 07:57 UTC
    my @rows = $tree->look_down (style => '128px', width => '160px');

    True laziness is hard work
      look_down works on html attributes, width is a css attribute
      #!/usr/bin/perl -- use strict; use warnings; use HTML::TreeBuilder; my $html = '<html><body> <span style="height:128px;width:160px">bob</span> </body></html>'; my $tree = HTML::TreeBuilder->new(); $tree->parse( $html ); print $tree->look_down('style',qr/\Q128px;width:160px\E/i)->dump; __END__ <span style="height:128px;width:160px"> @0.1.0 "bob"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2015-07-07 20:06 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