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

I am doing some scraping with WWW::Mechanize::find_all_inputs I wanted to update some info in the 3rd form on a page. I am having trouble accessing the 3rd form. When I print out the inputs the @c_inputs array only has the first form in it.
my @c_inputs = $mech->find_all_inputs(); foreach my $str (@c_inputs){ print STDERR Dumper($str); } print STDERR "That was for PAGE: ".$mech->uri."\n";
How do I point find_all_inputs to proper form, since it only seems to pick up the first form on the page? I did try to select the form first then do run on that, but was unsuccessful.
my @c_inputs = $mech->form_name('account')->find_all_inputs(); foreach my $str (@c_inputs){ print STDERR Dumper($str); }

Replies are listed 'Best First'.
Re: WWW::Mechanize and forms
by ikegami (Patriarch) on Dec 11, 2007 at 19:47 UTC

    find_all_inputs is documented to work on the current form.

    It wasn't hard to find methods that set the current form: form_number, form_name and form_with_fields.

    Note that form_name returns a form, while find_all_inputs needs to be called on a Mechanize object.

    $mech->form_name('account'); my @c_inputs = $mech->find_all_inputs();

    Untested. Just going by the docs.

      You're right, it wasn't hard to find the methods. I just misunderstood what I was reading. Thanks you for pointing out how to properly make the calls.