Mojo::UserAgent: get only the text

587 views Asked by At
use WWW::Mechanize;

my $mech = WWW::Mechanize->new;

$mech->get( $url );
say $mech->text;

How could I get the same result with Mojo::UserAgent?
I tried this, but it doesn't return the same:

use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;

say $ua->get( $url )->res->dom->all_text;
2

There are 2 answers

0
daxim On BEST ANSWER

Simply repeat what method text does: see as_text in HTML::Element.

0
bvr On

You can try

$ua->get( $url )->res->dom->all_text(0);

for untrimmed output. Or you may need some kind of traversal over child nodes.