开发者

perl get session cookie

开发者 https://www.devze.com 2023-03-22 07:31 出处:网络
is not wo开发者_C百科rk for some cookie #!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent;

is not wo开发者_C百科rk for some 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;

when cookie is like this ( from firebug )

name  value    
PREF  ID=00349dffbc142a77:FF=0:LD=en:CR=2:TM=1311217451:LM=1311217451:S=QKw9G4vAwl19Me4g

mycookies.txt is

#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

but for some site when cookie look like this

name         value
verify       test
guest_id     131099303870438180
PHPSESSID    7s99iq1qcamooidrop4iehcv32

nothing in mycookies.txt

how to fix it.

thank you.


Your first cookie is a domain cookie with expiry in the future. So it gets written to the cookie jar.

The second cookie is a session cookie, and expires when the program closes. It gets kept in memory, and does not get written to the jar.


I realize this is a bit late. The checked answer only describes why you have this problem. To actually "fix" the problem you need to look into the ignore_discard parameter for HTTP::Cookies.

0

精彩评论

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