Home > Archive > LibWWW > December 2005 > Dynamic Forms, Javascript (what else!) and WWW::Mechanize
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Dynamic Forms, Javascript (what else!) and WWW::Mechanize
|
|
| Peter Stevens 2005-09-03, 7:57 am |
| 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.pm 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
| |
| Gisle Aas 2005-09-04, 7:57 am |
| Peter Stevens <peter.stevens@ch-open.ch> 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.pm 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, "http://www.example.com");
<form>
<input name="foo" value=1>
</form>
EOT
$f->push_input("text", { name => "bar" });
$f->value(bar => 2);
print $f->click->as_string;
Regards,
Gisle
| |
| Peter Stevens 2005-09-04, 6:58 pm |
|
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
| |
| Peter Stevens 2005-12-09, 8:20 am |
| 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:
>
>
| |
| Gisle Aas 2005-12-12, 7:25 pm |
| Peter Stevens <peter.stevens@ch-open.ch> writes:
> Is there now an official interface to do this?
No. $form->push_input is still undocumented. Patches welcome.
--Gisle
|
|
|
|
|