[英]Perl Click Button with WWW::Mechanize
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. 我不熟悉使用Perl进行网络抓取,并且尝试通过填写用户名和密码字段并单击提交来提交页面。 I inspected the HTML code of the button in question, and it looks like:
我检查了有问题的按钮的HTML代码,它看起来像:
<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. 我读到
WWW::Mechanize
无法处理JavaScript,但是我不确定我正在查看的代码是JavaScript还是实现错误。 I tried $mech->click_button("Sign In");
我试过
$mech->click_button("Sign In");
halfheartedly, but received the error that no such field existed. 全心全意,但是收到了一个错误,即没有这样的字段存在。
Any ideas? 有任何想法吗?
Your button doesn't have name
attribute that's why I'm sure there is no need to click it . 您的按钮没有
name
属性,这就是为什么我确定没有必要单击它的原因 。 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. 查看有关
click_button
方法的文档 。 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. <input>
的value
属性不是标识符。 In the case of a submit
button, this is just the text on the button. 对于
submit
按钮,这只是按钮上的文本。
If you simply want to submit a form, you may just want submit_form
. 如果您只想提交表单,则可能只需要
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. 如果要单击一个按钮,但此按钮没有标识
name
,则可能要使用click_button
提供的功能。 You could specify 您可以指定
$mech->click_button(value => "Sign In");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.