WWW::Mechanize, submit_form, and the button parameter

WWW::Mechanize, submit_form, and the button parameter

am 07.11.2006 01:04:46 von edaly

Hey, all. We use WWW::Mechanize a lot, and there's a
particular situation that seems to crop up quite often, so I
figured I'd ask if there's a Better Way To Do It.

We often find ourselves working with websites that have
"Previous", "Next", and "Jump" buttons. The problem, of
course, is that all three forms are identical, save the
value of their "page" parameters and the text on their
buttons. The forms don't have names, and their
form_numbers are rarely static, so those options are off
the table. We basically find and submit the "Next" form by
doing this:

my $form;
my $found_next_button;

do {
# Stuff, then...

$form = 1;
$found_next_button = 0;

for ($mech->forms) {
my $input = $_->find_input(undef, "submit");
if ($input->value eq 'Next Page') {
$found_next_button = 1;
last;
}
$form++;
}
} while $found_next_button && $mech->submit_form(form_number => $form);

That seems /awfully/ clumsy, but if I read Mechanize.pm
right, the button parameter to submit_form doesn't accept
hash values like click_button, so there's no way to say,
"Use the form with the button that says 'Next Page'". Is
this correct? Is there a better way?

____________________________________________________________
Eamon Daly