Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

HTML::Form getting button by id

by mhearse (Chaplain)
on Jul 09, 2012 at 18:40 UTC ( #980739=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on HTML::Form getting button by id
Select or Download Code
Replies are listed 'Best First'.
Re: HTML::Form getting button by id
by Corion (Pope) 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?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://980739]
Approved by tobyink
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2016-05-24 11:20 GMT
Find Nodes?
    Voting Booth?