I am extremely new to perl (PHP programmer by trade) but am trying to leverage the power of www::mechanize for a project at work.
We use the PowerSchool system for our students, but we want to add the ability for parents and students to change their password on their own (right now we have to do it and it's a paper process). Unfortunately, we cannot directly update the database, so I'm going to use perl to log in to the form, navigate to the correct page, fill out the password field with a new password, then click submit.
I have stumbled, however, on the very first part of this. The login page for powerschool has 2 fields, a username(hidden) and password, but the password field is generated by javascript, a la
<script language="JavaScript" type="text/javascript">document.write('<input type="password" name="password" value="" size="50">');</script>
If I set up my mechanize like this:
$mech->get("pw.html");
print $mech->content;
However, if I do a
print $mech->form_dump();
I do not see the password field, and any manipulations I try to do via the $mech commands result in the following error in my logs:
No such field 'password'
An example I found from another PowerSchool user has them using HTML::Form and they use a push_input command to force the name of the field to be password, so I guess I'm looking for one of the following:
Can WWW::Mechanize to something similar?
or
Can I use a hybrid approach of HTML::Form and WWW::Mechanize? If so, how do I let them communicate?
Thanks!
Protection again people like you doing things like this!
I'd attempt to post the data directly to the form's target as it doesn't appear to use any generated or hidden keys.
You can use Win32::IE::Mechanize which does support javascript and should be able to handle this type of task.
[search.cpan.org...]
I have never used it so I can't help there but take a look and see if will do what you want. It does require Win32::OLE so that would have to be installed as well.
Perl_Diver, I understand that mech doesn't support javascript. I was wondering if there was similar functionality as in HTML::Form where I can push a value onto a field (when I use mech to return the page contents, I do see the fields, so I know it's there), or is there a way that I can use HTML::Form to do the first part, and then once I log in get mech to continue?
I'm not really sure that, once I'm on the next page, if I can grab the cookie that was stored and whatnot...I'm still very new at all of this.
I will look into the ie version that you posted, though, and see if that can help.
Thanks!
If I were doing it, I'd first GET the login page. This will capture any cookies that the server send, session cookie for example.
Then try to POST the login data. If there is no more JavaScript to process this may work.
But really if the Win32::IE version will support the JavaScript I would try to use it, it's probably the best solution.