Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

WWW::Mechanize and Cookies

by buddyq (Initiate)
on May 02, 2005 at 02:44 UTC ( [id://453112]=perlquestion: print w/replies, xml ) Need Help??

buddyq has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys, I'm just learning perl and i'm trying to make a script that automatically navigates and logs me in to xmradio.com online and launches the player. If I had already logged in through a regular browser the cookies get set and the script runs great! If i delete the cookies, and run the script I get an error page from xmradio that you usually get when your logged out and try to reload the page. So, at this point it doesnt set a cookie for my username and pass. How do I set cookies using WWW::Mechanize? Or what is the best way to go about this? Thanks in advance, Buddy

Replies are listed 'Best First'.
Re: WWW::Mechanize and Cookies
by dorko (Prior) on May 02, 2005 at 03:42 UTC
    Hello buddyq,

    A quick Google for "WWW::Mechanize cookies" found an article by Chris Ball as the first result. I quote:

    As a note for your own experiments, WWW::Mechanize supports cookies - in that the requestor is a normal LWP::UserAgent object - but they aren't enabled by default. If you need to support cookies, then your script should call "use HTTP::Cookies; $agent->cookie_jar(HTTP::Cookies->new);" on your agent object in order to enable session-volatile cookies for your own code.
    NOTE: I haven't used cookies with WWW::Mechanize, but I've used them with LWP. So take this post with a grain of salt.

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
      NOTE: I haven't used cookies with WWW::Mechanize, but I've used them with LWP. So take this post with a grain of salt.

      I have used them and it works exactly as dorko's answer explain.

      Best regards

      -lem, but some call me fokat

        I use cookies with WWW::Mechanize, but not only saving cookies for the session, saving cookies for later sessions as set by the site's "remember me on this computer"* checkbox.

        my $browser = WWW::Mechanize->new( cookie_jar => { file => "$ENV{HOME}/.cookies.txt", autosave => 1 } );

        That script logged into the NY Times two years ago and has stayed logged in ever since.

        * It should be "remember me on this computer with this browser" of course, but what the hell...



        ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
        =~y~b-v~a-z~s; print
Re: WWW::Mechanize and Cookies
by kprasanna_79 (Hermit) on May 02, 2005 at 07:32 UTC
    Hai,
    Here i am submitting my ideas not the exact working code. Please try my ideas.
    use WWW::Mechanize; use HTTP::Cookies; $login = "http://xmradio.com?&username=buddyq&password=password"; $cookie_jar = HTTP::Cookies->new( file => "$ENV{'HOME'}/cookie.dat" +, autosave => 1); $mechanize=WWW::Mechanize->new(cookie_jar => {$cookie_jar}); $mechanize->get($login);
    After this i think u can browse thr various page...
    This is untested code and my ideas, so dont go literally with this rather use this idea.
    --prasanna.k

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://453112]
Approved by dorko
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-18 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found