sid_com
sid_com

Reputation: 25117

Mojo::UserAgent: get only the text

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;

Upvotes: 1

Views: 581

Answers (2)

bvr
bvr

Reputation: 9697

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.

Upvotes: 0

daxim
daxim

Reputation: 39158

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

Upvotes: 2

Related Questions