Search code examples
perldomwww-mechanizemojolicious

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;

Solution

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