Dynamic Forms, Javascript (what else!) and WWW::Mechanize
Dynamic Forms, Javascript (what else!) and WWW::Mechanize
am 03.09.2005 13:46:24 von peter.stevens
--------------060605050504050200080109
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi everyone,
[ Apologies is this is the repeat of a topic which has been addressed
earlier, but I couldn't find it ]
I am trying to use $mech to log in to www.sprint.com. This site was
recently merged with the Nextel site, so the site now presents a Form
asking you which service you want to log into. A javascript is executed
and depending on your selection it displays a series of fields which
allow you to log into that site.
Thanks to using Tamper Data, I know which variables I need to post. The
problem is that when the page is first displayed (i.e. before the
javascript [doesn't] execute, these form variables don't exist. They are
apparently created by the javascript. So when I try
$mech->field('min', $telno ) ;
I get an error from HTML::Form:
No such field 'min' at
/home/mmtest/local/lib/perl5/site_perl/5.8.5/WWW/Mechanize.p m line 1030
at /home/mmtest/local/lib/perl5/site_perl/5.8.5/HTML/Form.pm line 402
So it looks like I just need to convince HTML::Form to create some new
fields, but I couldn't find how to do this. Can anybody explain? Is
there are better way to address this problem?
Thanks in advance!
Peter
------------------------------------------------------------ ----------
Peter Stevens
Get you Cell Phone costs under control! www.MinuteWatcher.com
--------------060605050504050200080109--
Re: Dynamic Forms, Javascript (what else!) and WWW::Mechanize
am 04.09.2005 12:53:27 von gisle
Peter Stevens writes:
> The problem is that when the page is first displayed
> (i.e. before the javascript [doesn't] execute, these form variables
> don't exist. They are apparently created by the javascript. So when I
> try
>
> $mech->field('min', $telno ) ;
>
> I get an error from HTML::Form:
>
> No such field 'min' at
> /home/mmtest/local/lib/perl5/site_perl/5.8.5/WWW/Mechanize.p m line 1030
> at /home/mmtest/local/lib/perl5/site_perl/5.8.5/HTML/Form.pm line 402
>
> So it looks like I just need to convince HTML::Form to create some new
> fields, but I couldn't find how to do this. Can anybody explain?
You could try to use the undocumented 'push_input' method. It's not
doucmented because I did not think anybody would have a reason to
modify the form, but as this problem demonstrates there is certainly
use cases. HTML::Form should grow an official API to modify the form
structure.
This is a short demo of how you can add fields with the current
version:
#/usr/bin/perl -w
use strict;
use HTML::Form;
my $f = HTML::Form->parse(<
EOT
$f->push_input("text", { name => "bar" });
$f->value(bar => 2);
print $f->click->as_string;
Regards,
Gisle
Re: Dynamic Forms, Javascript (what else!) and WWW::Mechanize
am 04.09.2005 15:35:31 von peter.stevens
Gisle Aas wrote:
>
>This is a short demo of how you can add fields with the current
>version:
>...
>
>
Dear Gisle,
Nice little hack, thanks! This should solve the problem nicely. I've had
the problem before & I think it would be useful addition to the interface.
This page is being used to put a common sign-on in front of two merged
websites. The login dispatches to the corresponding real web server (of
which therse is still at least one for each of the two ex-companies). I
was able to find a "side-entrance". Each of the original web sites still
had a login page which I was able to access and use my old scripts,
essentially unchanged.
Thanks again,
Peter
--
------------------------------------------------------------ ----------
Peter Stevens
Get control of your cell phone usage www.MinuteWatcher.com
Re: Dynamic Forms, Javascript (what else!) and WWW::Mechanize
am 09.12.2005 13:40:37 von peter.stevens
Hi Gisle,
Well, I'm going to use your hack after all. It seems the behavior of the
'side-entrance' is different from the main entrance. (If you want to
know the details, I'll explain them off the list).
Is there now an official interface to do this?
Thanks again!
Peter
Peter Stevens wrote:
>
>
> Gisle Aas wrote:
>
>>
>> This is a short demo of how you can add fields with the current
>> version: ...
>
Re: Dynamic Forms, Javascript (what else!) and WWW::Mechanize
am 12.12.2005 19:04:38 von gisle
Peter Stevens writes:
> Is there now an official interface to do this?
No. $form->push_input is still undocumented. Patches welcome.
--Gisle