http://www.perlmonks.org?node_id=980739

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

I'm doing some screenscraping. Trying to submit a form using the HTML::Form->click method. The only problem is: the button doesn't have a name... only an id. I'm unable to get the button using:
my $login; foreach (HTML::Form->parse($self->{resp})) { #if ($_->find_input('btnLogin')) { print Dumper($_); if ($_->find_input('Login', 'button')) { $login = $_; last; } } die $! if not $login;
This is what I get by doing print Dumper($_);
{ '/' => '/', 'value_name' => '', 'tabindex' => '4', 'value' => 'Login', 'class' => 'login_button butto +n', 'id' => 'btnLogin', 'type' => 'button' },
Can someone help? Thanks.

Replies are listed 'Best First'.
Re: HTML::Form getting button by id
by Corion (Patriarch) on Jul 09, 2012 at 19:09 UTC

    The documentation for ->find_input in HTML::Form says:

    This method is used to locate specific inputs within the form. All inputs that match the arguments given are returned. In scalar context only the first is returned, or undef if none match.

    If $selector is specified, then the input's name, id, class attribute must match. A selector prefixed with '#' must match the id attribute of the input. A selector prefixed with '.' matches the class attribute. A selector prefixed with '^' or with no prefix matches the name attribute.

    How would you phrase it so that it is more clear how to search an input by its id attribute?

      Well, I did scan the HTML::Form perldoc before making this post. I would say that the doc could be more digestible by using the term pattern instead of selector. Not that I'm making any excuses. And (don't worry, I'm already wearing my dunce cap) my code is still broke:
      my $login; foreach (HTML::Form->parse($self->{resp})) { if ($_->find_input('#btnLogin')) { $login = $_; last; } } die $! if not $login;

        What part of your code does not work, and how does it fail? Also, what is the input HTML?