Syntactic Confectionery Delight PerlMonks

by PerlSufi (Friar)
 on Jul 05, 2013 at 15:26 UTC ( #1042736=perlquestion: print w/ replies, xml ) Need Help??
PerlSufi has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,
I want to extract cookies from a website. Particularly, JSESSIONID cookie. However, when I run the code below, nothing turns up in my file except '#LWP-Cookies-1.0'.
use LWP::UserAgent;

my $cookie_jar = HTTP::Cookies->new( file => 'C:\path\to\cookies.dat', + autosave=> 1); my$browser = LWP::UserAgent->new( );

$browser->cookie_jar($cookie_jar );

$browser->get('https://example.com'); [download] Any insight into what I'm doing wrong is greatly appreciated! Comment on Getting Cookies Download Code Re: Getting Cookies by kennethk (Abbot) on Jul 05, 2013 at 16:02 UTC Your code above is correct, assuming that your cookie isn't timing out (i.e. isn't a session cookie). Under normal circumstances, session cookies are discarded immediately upon exit from your 'browser'. If you want to force holding onto the cookie, use ignore_discard in your constructor: my$cookie_jar = HTTP::Cookies->new(file => 'C:\path\to\cookies.dat',
autosave=> 1,
[download]

#11929 First ask yourself How would I do this without a computer?' Then have the computer do it the same way.

Thanks, kennethk. That worked for me. :)
The cookie is different from what my browser gives me so I'm working on how to get that now
Firebug, the free Firefox plug-in, makes that easy.

#11929 First ask yourself How would I do this without a computer?' Then have the computer do it the same way.

by Anonymous Monk on Jul 06, 2013 at 06:46 UTC

Well, for some reason you think https://example.com/ will set some cookies for you, and not, for example, an image embedded inside html returned by https://example.com/ or javascript embedded inside or css embedded inside or one or more combinations of both

Also, could be https://example.com/ doesn't like the headers you're sending, so it doesn't give you a cookie

Also, it could be a proxy of some sort between you and https://example.com/ interfering

Also, it could be some firewall or antivirus or somesuch interfering on your machine (or on proxy between you and https://example.com/ )

Also, it could be anything :)

Create A New User
Node Status?
node history
Node Type: perlquestion [id://1042736]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-05-30 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?