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

Hi Monks,

I m trying to access a url using mechanize. The url redirects me to a secure login and i must authenticate myself to get in. I want to automate this login process but the login page is created using Javascript:

document.write("<table border=0 align=center width=100%>"); document.write("<tr>"); document.write("<th align=right id=\"lblUserID\">"); document.write(getUserIDText(bShowBD)); document.write("</th>"); //document.write("<td align=left><input type=\"text\" name=\"useri +d\" value=\"\" maxlength=\"128\" size=\"9\"></td>"); document.write("<td align=left><input type=\"text\" name=\"userid\ +" value=\"" + getUserName() + "\" maxlength=\"128\" size=\"9\"></td>" +); document.write("</tr>"); document.write("<tr>"); document.write("<td colspan=2>"); document.write("<input type=\"hidden\" name=\"username\" value=\"\ +" maxlength=\"128\" size=\"9\">"); document.write("</td>"); document.write("</tr>"); document.write("<tr>"); document.write("<th align=right><LABEL ID=lblPWD>Password:</LABEL> +</th>"); document.write("<td align=left><input type=\"password\" name=\"pas +sword\" value=\"\" maxlength=\"46\" size=\"20\">"); document.write("</td>"); document.write("</tr>"); document.write("<tr>"); document.write("<td colspan=2>"); document.write("<input type=\"hidden\" name=\"login-form-type\" va +lue=\"pwd\">"); document.write("</td>"); document.write("</tr>"); document.write("<tr>"); document.write("<td align=center colspan=2><input type=\"submit\" +name=\"btnSubmit\" value=\" OK \" onClick=\"if (setReqURL()==false) + return false; if (checkCookiesAtField(userid)) return true; else ret +urn false;\"></td>"); document.write("</tr>");

from whatever i have read this isn't possible.But isn't there some hack?

Thanks in Advance.

Replies are listed 'Best First'.
Re: Automate WebLogin
by marto (Cardinal) on Jan 21, 2011 at 16:11 UTC
Re: Automate WebLogin
by Anonymous Monk on Jan 21, 2011 at 16:11 UTC
Re: Automate WebLogin
by Anonymous Monk on Jan 21, 2011 at 16:14 UTC

    Wow, that javascript is just... wow.

    From the looks of it, you can parse that with your eyeballs, and just hard code your script to submit the appropriate form info.

      But but but, that would make him a hacker!

      Yeah that is what i thought(parsing the javascript and hardcoding values).But, how do i hardcode the click:

      document.write("<td align=center colspan=2><input type=\"submit\" name +=\"btnSubmit\" value=\" OK \" onClick=\"if (setReqURL()==false) ret +urn false; if (checkCookiesAtField(userid)) return true; else return +false;\"></td>");
      Thanks,

        Learn what your browser sends, then send that from Perl. For example, using the Live HTTP Headers extension. Or learn Javascript and how it interacts with the HTML DOM, and what the click for a submit button does. Or just modify the code to find it out.