Mojo::UserAgent:仅获取文本
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需重复方法
text
确实:请参阅as_text
中HTML::元素。Simply repeat what method
text
does: seeas_text
in HTML::Element.您可以尝试
未修剪的输出。或者您可能需要对子节点进行某种遍历。
You can try
for untrimmed output. Or you may need some kind of traversal over child nodes.