我有Perl& LWP书,但如何设置用户代理字符串?
这就是我所拥有的:
use LWP::UserAgent; use LWP::Simple; # Used to download files my $u = URI->new($url); my $response_u = LWP::UserAgent->new->get($u); die "Error: ",$response_u->status_line unless $response_u->is_success;
任何建议,如果我想像我这样使用LWP :: UserAgent?
解决方法
从
LWP cookbook:
use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("$0/0.1 " . $ua->agent); # $ua->agent("Mozilla/8.0") # pretend we are very capable browser $req = new HTTP::Request 'GET' => 'http://www.sn.no/libwww-perl'; $req->header('Accept' => 'text/html'); # send request $res = $ua->request($req);