Mojo::UserAgent:仅获取文本

发布于 2024-12-31 21:32:09 字数 336 浏览 5 评论 0原文

use WWW::Mechanize;

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

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

如何使用 Mojo::UserAgent 获得相同的结果?
我尝试了这个,但它没有返回相同的结果:

use Mojo::UserAgent;

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

say $ua->get( $url )->res->dom->all_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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2025-01-07 21:32:09

只需重复方法text 确实:请参阅 as_text 中HTML::元素

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

动次打次papapa 2025-01-07 21:32:09

您可以尝试

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

未修剪的输出。或者您可能需要对子节点进行某种遍历。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文