开发者

Problems with Perl Mechanize and Proxies

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 $mec开发者_Go百科h = 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.


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜