Perl Mechanize 和代理的问题

发布于 2024-10-06 12:46:53 字数 893 浏览 2 评论 0原文

我已经为此让自己沮丧了太多个小时了。我认为这应该很简单,但我显然有一些根本性的错误。我已阅读:

我已阅读 cpan 文档: WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod libwww-perl-5.837/lib/LWP/UserAgent.pm

以及我可以在 Google 上找到的所有示例代码或文章。

这是我第一次在 Stack Overflow 上寻求帮助。提前感谢您的帮助。这是代码:

#!/usr/bin/perl

use WWW::Mechanize;

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0" );

my $proxy = 'http://fetch4.me';

$mech->no_proxy('localhost');
$mech->proxy(['http', 'https', 'gopher'], $proxy) or die $!;
$mech->get('http://www.google.com');

print $mech->uri(),"\n";
print $mech->content(),"\n";
print $mech->text(),"\n";
print $mech->status(),"\n";

这是输出:

http://www.google.com
<html>Apache is functioning normally</html>

Apache is functioning normally
200

我在这里没有想法了。这段代码对你有用吗?它会产生相同的结果吗?有什么问题吗? >。<

感谢您抽出时间。

I've been frustrating myself with this for way too many hours. I think this should be simple but I obviously have something fundamental wrong. I've read:

I've read the cpan docs for :
WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod
libwww-perl-5.837/lib/LWP/UserAgent.pm

And every bit of sample code or article I could find on Google.

This is my first time looking for help on Stack Overflow. Thanks for your help in advance. Here is the code:

#!/usr/bin/perl

use WWW::Mechanize;

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0" );

my $proxy = 'http://fetch4.me';

$mech->no_proxy('localhost');
$mech->proxy(['http', 'https', 'gopher'], $proxy) or die $!;
$mech->get('http://www.google.com');

print $mech->uri(),"\n";
print $mech->content(),"\n";
print $mech->text(),"\n";
print $mech->status(),"\n";

Here is the output:

http://www.google.com
<html>Apache is functioning normally</html>

Apache is functioning normally
200

I'm running out of ideas here. Does this code work for you? Does it produce the same results? What's wrong with it? >.<

Thank you for your time.

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

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

发布评论

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

评论(2

陈独秀 2024-10-13 12:46:54

问题似乎出在服务器 fetch4.me 上。例如,尝试使用

my $proxy = 'http://124.207.162.87:80';

The problem seems to be in the server fetch4.me. Try, for instance, instead

my $proxy = 'http://124.207.162.87:80';

春夜浅 2024-10-13 12:46:54

是否说:

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0", noproxy => 1 );

有帮助?

该文档暗示您需要这样做以避免隐式调用 LWP 的 env_proxy。

Does saying:

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0", noproxy => 1 );

help?

The doc implies you need to do that to avoid an implicit call to LWP's env_proxy.

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