Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

WWW::Mechanize login

by LordScinawa (Novice)
on Sep 16, 2009 at 23:07 UTC ( [id://795728]=perlquestion: print w/replies, xml ) Need Help??

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

Hi All! I'm having big problem with a login form. I obviously use WWW::Mechanize, but the login button is not part of the form. Actually the webpage is this:
<table border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table border="0" cellspacing="10" cellpadding="0"> <form method="post" target="_top" action="../jsp/index.jsp +" name="TheForm" onSubmit="return sendForm();"> <input type="hidden" name="password" value="" /> <input type="hidden" name="rememberid" value="" /> <input type="hidden" name="pid" value="0"/> <input type="hidden" name="challenge" value="" /> <tr> <td><font face="Arial" size="2" color=#ffffff><b>&nbsp +;Nome utente</b></font></td> <td><input style="width:120px;" type="text" name="us +erid" size="15" maxlength="25" tabindex="1" value=""/></td> </tr> </form> <form method="post" target="_top" action="../jsp/index.jsp +" name="loginForm" onSubmit="return sendForm();"> <input type="hidden" name="userid" value=""/> <input type="hidden" name="rememberid" value=""/> <input type="hidden" name="pid" value="0"/> <input type="hidden" name="bla" value=""/> <tr> <td><font face="Arial" size="2" color=#ffffff><b>&nbsp +;Password</b></font></td> <td><input style="width:120px;" type="password" name=" +password" size="15" tabindex="2" maxlength="25" value=""/></td> </tr> </form> <tr> <td colspan="2" align="right"> <a href="javascript:clickLogin()" onMouseOver="ret +urn statusMsg('Login');" onMouseOut="return statusMsg();"><img src=". +./images/it/button_login.gif" border="0" alt="Login" tabindex="3"></ +a></td>
and my code is this:
$mech->form_number(1); $mech->set_fields ( 'userid' => $user) ; $mech->form_number(2); $mech->set_fields('password' => $password); $mech->form_number(1); $mech->submit_form(); #dont' work $mech->click(); #don't work $mech->follow_link( text_regex => qr/Login/i ); #don't work
i'have tried all combination of submit_form (with fields) & something similar, but i don't think these methods are suitable for pressing a link-image-button.. Is this because www::mechanize didn't support javascript? :| Tanx in advice so much!

Replies are listed 'Best First'.
Re: WWW::Mechanize login
by venkatesan_G02 (Sexton) on Sep 17, 2009 at 11:00 UTC
    As mentioned earlier, WWW::Mechanize does not work with javascript enabled pages. You have to re-create the javascript function in perl if you have to use WWW::MEchanize.

    Alternatively, you can use Win32::IE::Mechanize (if you are using Internet Explorer) or Mozilla::Mechanize (if you have firefox).

    You can even try www::selenium.
Re: WWW::Mechanize login
by Anonymous Monk on Sep 16, 2009 at 23:32 UTC
    Is this because www::mechanize didn't support javascript?

    Yes.

Re: WWW::Mechanize login
by pemungkah (Priest) on Sep 18, 2009 at 23:09 UTC
    If you can figure out what URL the Javascript accesses, you can imitate that with WWW::Mechanize. The LiveHTTPHeaders Filrefox extension can be invaluable for this kind of thing; not only do you see the requests and responses, but you get a chance to see what's comg by in the way of cookies and the like.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found