0

我是使用 Perl 进行网络抓取的新手,我正在尝试通过填写用户名和密码字段并单击提交来提交页面。我检查了相关按钮的 HTML 代码,它看起来像:

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

我读到WWW::Mechanize无法处理 JavaScript,但我不确定我正在查看的代码是 JavaScript,还是我的实现是错误的。我$mech->click_button("Sign In");三心二意地尝试,但收到不存在此类字段的错误。

有任何想法吗?

4

3 回答 3

3

您的按钮没有name属性,这就是为什么我确定没有必要单击它。您需要的只是将您的字段提交到表单

$mech->submit_form(
    with_fields => {
        your_username_field => $user,
        your_password_field => $password,
        .....
    },
);
于 2013-07-14T10:11:05.687 回答
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.

于 2013-07-14T09:07:02.677 回答
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");
于 2013-07-14T09:07:59.977 回答