1

Just using this Mojo::DOM for the first time and having trouble to extract information based on a previous tag. Looking for a way to grab 'The description'.

#!/usr/bin/perl
require v5.10;
use feature qw(say);
use Mojo::DOM;

my $html = q(<p><strong>Description</strong></p><p>The description</p> <p><strong>Usage</strong></p><p>How to use this tool</p>);

my $dom = Mojo::DOM->new( $html );

say $dom->find('p strong')->map('text')->join("\n"); # Description

Gert
  • 25
  • 5

1 Answers1

3

To get the first one, you can do this

say $dom->at('p strong')->parent->next->text;

Or to get all of them

say $dom->find('p strong')->map(sub { $_->parent->next->text })->join("\n");
elcaro
  • 2,227
  • 13
  • 15
  • Thanks for your help. I ended up using something like: `for my $e (Mojo::DOM->new($data)->find('a, p strong, p')->each) { say $e->all_text;}` – Gert Oct 01 '20 at 19:25