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

This question has been asked a number of times before and I've read them and actually tried doing it once a while back (different project but even then, it never did it right. It never logged in and stayed logged in).

I want to create a script that logs into Neopets.com. It has a two page login (enter your username on page 1, enter your password on the page it redirects you to). I need to STAY logged in with the cookie or session that they send out so I can run a few other page scrapes.

What module(s) would be best to login with 2 forms and stay logged in so I can navigate with my bot where it's supposed to go?

Thank you.

  • Comment on Login into a website with cookies/session id

Replies are listed 'Best First'.
Re: Login into a website with cookies/session id
by johnnywang (Priest) on Sep 30, 2005 at 22:45 UTC
    WWW::Mechanize, it has everything you need, to enable cookie, do something like:
    my $agent = WWW::Mechanize->new(); $agent->cookie_jar(HTTP::Cookies->new);
      Thanks for your help. After reading some of the docs on this module it shows how to follow_link as if you were following an HTML link.

      This is a two page form, how do I then submit the information on the next page? Would I just put in the next form code (as seen below)?

      #!/usr/bin/perl use warnings; uses strict; use CGI qw/:standard/; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->submit_form( form_number => 1, fields => { username => 'user' } ); #### # the previous form redirects us to a new page/form. This # should fill out that form the, right? #### $mech->submit_form( form_number => 1, fields => { password => '12345' } ); #### # at this time, cookies should be saved allowing me to use # Mechanize to pull back ANY $url I want on Neopets.com. ####
Re: Login into a website with cookies/session id
by Cody Pendant (Prior) on Sep 30, 2005 at 22:47 UTC
    You need WWW::Mechanize -- and you need to be able to read the HTML source of the relevant pages to see what the form and field names are, of course.

    It should handle the cookies for you as well.



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print