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}); }