perl捕捉cookies

#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;

my $cookies = HTTP::Cookies->new(
        file => "cookies.txt",
        autosave => 1,
        );
my $ua = LWP::UserAgent->new();
$ua->cookie_jar($cookies);

my $req = HTTP::Request->new(GET => "http://www.baidu.com/");
my $resp = $ua->request($req);
if (( $resp->code() >= 200 ) && ($resp->code() < 400)) {
        print "yes\n";
} else {
        print "Error: ". $resp->status_line. "\n";
}
 

你可能感兴趣的:(Web,Cookies,perl)