I've written a scraper with WWW::Mechanize.

It logs in to a website every time I run it and returns a table of data.

So, now I'm thinking, why does it have to log in every time?

My browser doesn't have to log in every time. There's a timeout of an hour.

I've got this:

my $mech = WWW::Mechanize->new( cookie_jar => { file => "/path/to/cookies.txt", autosave => 1 } );
in my code, and that file is being written to every time the script runs, but it's empty except for "#LWP-Cookies-1.0" at the top.

There's no "remember me" option on this website, so they're only for-this-session type cookies, but why doesn't Mech save those for me? That way the website would let my script return five minutes later and see it as still logged in, just like it does with my browser.

Maybe there's something about session cookies I don't understand? Any help gratefully received.



Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

In reply to Stay logged in between requests with WWW::Mechanize by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.