OK, so I'm using WWW::Mechanize to try to login to a site so that I can parse some of the content on the site. Unfortunately, it looks like I'm not successfully 'logging in'.
The form on the site looks like this:
<form onSubmit="return validLogin( this );" action="/servlet/LoginServ +let" METHOD="post" name="enterLogin"> <input type="text" tabindex="1" size="8" name="loginId"> <input type="password" tabindex="2" size="8" name="Password"> <input TYPE="hidden" name="action" value="loginFrame"> <input type="hidden" name="app" value=""> <input type="hidden" name="sessType" value="new"> <input type="image" tabindex="3" src="/homepage/gobutton.gif" border=" +0"> </form>
I used the update_html method to remove "onSubmit=return validLogin( this );" so that it doesn't call the javascript (it just changes the username/password to uppercase).
Here is what my code looks like:
The code above prints the login page ....meaning, it didn't really log me in.use LWP::Simple; use WWW::Mechanize; my $m = WWW::Mechanize->new( autocheck=>1 ); $agent->cookie_jar(HTTP::Cookies->new); # point to the url of the login form $m->get("http://www.mydomain.com/servlet/LoginServlet"); my $html = $m->content; $html =~ s[onSubmit="return validLogin\( this \);"][]g; $m->update_html($html); $m->submit_form( form_name => "enterLogin", fields => { loginId=> "XXXXXXX", Password=> "YYYYYYY", action=> "loginFrame", app=> "", sessType=> "new" } ); print "success?:"; print $m->success(); print "\n"; my $url1 = "http://www.mydomain.com/private/Servlet?var1=apples&var2=o +ranges"; $m->get($url1); print $m->content;
Any ideas why this isn't working? Am I supposed to be doing something with the input/image tag?
thank you!
2006-06-08 Retitled by GrandFather, as per Monastery guidelines
Original title: 'Not logging in'
In reply to Script using WWW::Mechanize fails to log in by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |