Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Mojo::DOM find tag after another tag

by Anonymous Monk
on May 29, 2016 at 00:04 UTC ( [id://1164422]=note: print w/replies, xml ) Need Help??


in reply to Mojo::DOM find tag after another tag

in DOM, if they're not parent and child, tags/tokens are siblings
  • Comment on Re: Mojo::DOM find tag after another tag

Replies are listed 'Best First'.
Re^2: Mojo::DOM find tag after another tag
by Anonymous Monk on May 29, 2016 at 01:43 UTC
    $ perl -Mojo -le " my $dom = x(b(q{2.html})->slurp); for my $img ( $d +om->find(q{h1 ~ img})->each ){ print $img->attr(q{src}); } " 333 444
      Nice script, but it fails if between H1 and IMG occur other tags.
      my $data = 'yada...yada...yada.. <img src="111"> yada...yada...yada.. <img src="222"> yada...yada...yada.. <h1>Some title</h1> yada...yada...yada.. <a href="444444"> <img src="333"> yada...yada...yada.. <img src="444">'; my $dom = Mojo::DOM->new($data); for my $img ( $dom->find(q{h1 ~ img})->each ) { print $img->attr(q{src}); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found