javascript - Perl Click Button with WWW::Mechanize - Stack Overflow

admin2025-04-17  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?

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?

Share asked Jul 14, 2013 at 8:58 aqueminiaquemini 9602 gold badges13 silver badges32 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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,
        .....
    },
);

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.

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");
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744857609a270922.html

最新回复(0)