不是爲某些cookie的工作Perl中獲得會話cookie
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use HTTP::Cookies;
my $ua = LWP::UserAgent->new;
# Define user agent type
$ua->agent('Mozilla/4.0');
# Cookies
$ua->cookie_jar(
HTTP::Cookies->new(
file => 'mycookies.txt',
autosave => 1
)
);
# Request object
my $req = GET 'http://www.google.com';
# Make the request
my $res = $ua->request($req);
# Check the response
if ($res->is_success) {
print $res->content;
} else {
print $res->status_line . "\n";
}
exit 0;
時,cookie是這樣的(從螢火蟲)
name value
PREF ID=00349dffbc142a77:FF=0:LD=en:CR=2:TM=1311217451:LM=1311217451:S=QKw9G4vAwl19Me4g
mycookies.txt是
#LWP-Cookies-1.0
Set-Cookie3:
PREF="ID=00349dffbc142a77:FF=0:TM=1311217451:LM=1311217451:S=QKw9G4vAwl19Me4g";
path="/"; domain=.google.com; path_spec; expires="2013-07-20 03:04:11Z"; version=0
但對於一些網站當cookie看起來像這樣
name value
verify test
guest_id 131099303870438180
PHPSESSID 7s99iq1qcamooidrop4iehcv32
沒有在mycookies.txt中
如何解決它。
謝謝。
這也解決了我的問題,在'HTTP :: Cookies-> new'參數中添加'ignore_discard => 1' –