First, I have to say that despite the fact that my program still doesn't work, I have learnt so much from asking my questions at Perlmonks. Thank you Monks!

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:

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;
The code above prints the login page ....meaning, it didn't really log me in.

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

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.