1

I am trying to login to a website using perl. I have tried all the options - LWP::Mechanize, LWP::UserAgent, etc. but still have not been able to login successfully. I get a response code of 200 which means successful but how will i move on to the next page? Any help will be appreciated.

PSA
  • 53
  • 1
  • 3
  • 13
  • Possible duplicate of http://stackoverflow.com/questions/6186258/access-various-pages-of-website-using-perl. – Brant Olsen May 16 '12 at 19:05
  • There could be many things going on. You'll have to show a lot more than you have. – brian d foy May 16 '12 at 20:33
  • We can't tell what's wrong with your code if you show us no code. We can't read your mind. Also, the package is WWW::Mechanize, not LWP::Mechanize. Have you read the Mechanize FAQ? Have you seen the first question that says that Mechanize does not handle JavaScript? Could the page that you're logging into require JavaScript? – Andy Lester Sep 12 '13 at 19:06

1 Answers1

1

Make sure you are using cookies with LWP

$ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" });

after the login just have the $ua request the next page.

If the login redacts you to another page and you want to get that then use

$ua->requests_redirectable

For more info check out the docs at http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/UserAgent.pm

zortacon
  • 617
  • 5
  • 15
  • here's the code i am using $url = 'http://www.optionslam.com/index.html'; $username = 'abc'; $password = 'def'; $browser = LWP::UserAgent->new('Mozilla'); $browser->credentials("www.optionslam.com:80","realm-name",$username=>$password); $response=$browser->get($url); $code=$response->code; #print $code; if ($code = 200) { $content = $browser->get ("http://www.optionslam.com/myaccount.html"); $content1 = $response->content; print $content1; $content1 should contain the logged in page, but the source code does not show the details of the user name and password.am i doing something wrong? – PSA May 18 '12 at 19:14