Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Getting Cookies

by kennethk (Monsignor)
on Jul 05, 2013 at 16:02 UTC ( #1042738=note: print w/ replies, xml ) Need Help??


in reply to Getting Cookies

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, ignore_discard => 1);
The flag is documented in HTTP::Cookies, and read HTTP_cookie#Session_cookie to learn more about the behavior.

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


Comment on Re: Getting Cookies
Select or Download Code
Re^2: Getting Cookies
by PerlSufi (Pilgrim) on Jul 05, 2013 at 16:45 UTC
    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.

      I'd also mention that, instead of storing cookies to disk, you can use Data::Dumper to look at your cookie jar contents.


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

        Ty, kennethk. I have been using HTTP live headers. I forgot firebug did that. I actually want my script to get them automatically. I will be using WWW::Mechanize::Firefox to do crawl the site. I need the JSESSIONID to be a part of an HTTP get request.
        Oh. It turns out that WWW::Mechanize::Firefox doesn't save cookies to the jar? :(
        Thanks again for recommending the Data::Dumper to get those cookies. I am another step closer to automating the page. Now I think I need to use a regex to match for the JSESSIONID and concatenate it into my get request.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1042738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2014-09-21 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls