Perl Mechanize 和代理的问题
我已经为此让自己沮丧了太多个小时了。我认为这应该很简单,但我显然有一些根本性的错误。我已阅读:
我已阅读 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题似乎出在服务器 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';
是否说:
有帮助?
该文档暗示您需要这样做以避免隐式调用 LWP 的 env_proxy。
Does saying:
help?
The doc implies you need to do that to avoid an implicit call to LWP's env_proxy.