0

I'm new to web scraping with Perl, and I'm trying to submit the page by filling in username and password fields, and clicking submit. I inspected the HTML code of the button in question, and it looks like:

<input type="submit" class="button formSubmission" value="Sign In">

I read that WWW::Mechanize can't handle JavaScript, but I'm not sure if the code I'm looking at is JavaScript, or my implementation is just wrong. I tried $mech->click_button("Sign In"); halfheartedly, but received the error that no such field existed.

Any ideas?

aquemini
  • 950
  • 2
  • 13
  • 32

3 Answers3

3

Your button doesn't have name attribute that's why I'm sure there is no need to click it. What you need is just submit your fields to the form:

$mech->submit_form(
    with_fields => {
        your_username_field => $user,
        your_password_field => $password,
        .....
    },
);
gangabass
  • 10,607
  • 2
  • 23
  • 35
2

Take a look at the documentation for the click_button method. It lists several possible ways to look up the button you want to click. Your button doesn't have a name but it does have a value, so

$mech->click_button( value => "Sign In" );

should do it.

friedo
  • 65,762
  • 16
  • 114
  • 184
  • It returns the error `Can't call method "header" on an undefined value at /Library/Perl/5.12/WWW/Mechanize.pm line 2471`. – aquemini Jul 14 '13 at 09:11
1

The value attribute of an <input> is no identifier. In the case of a submit button, this is just the text on the button.

If you simply want to submit a form, you may just want submit_form.

If you want to click a button, but this button does not have a identifying name, then you may want to use the features click_button offers. You could specify

$mech->click_button(value => "Sign In");
amon
  • 57,091
  • 2
  • 89
  • 149