网站点击按钮 - Perl的WWW ::机械化 [英] Website button click - Perl WWW::Mechanize

查看:364
本文介绍了网站点击按钮 - Perl的WWW ::机械化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Perl脚本来自动与网站的互动。

我用模块WWW ::机械化,实现我的设计。但我不能用命令如下执行我的perl脚本按一下按钮。

  $ mech->点击($按钮[,$ X,$ Y])
$ mech-> click_button(...)

这是因为这个按钮不属于任何形式的没有名字,我不能打电话或在我的perl脚本找到这个按钮。我怎样才能使人们有可能在我的perl脚本就像我与浏览器的交互,点击这个按钮?谢谢你。

 <按钮类=键交易ID =结帐现在><跨度>立即结账< / SPAN>< /按钮>


解决方案

如果按钮不属于任何形式的它应该有onclick事件的定义,像@Bilzac和@hijack提及。在这种情况下,你是不是能够重现浏览器的行为,因为 WWW ::机械化只做HTML分析。

使用JavaScript事件处理它更容易实现浏览器的网络活动,而不是整个执行JavaScript事件和DOM的互动。

I try to use the perl script to automate the interaction with a website.

I use module WWW::Mechanize to realize my design. But I cannot perform the button click in my perl script by using command as below.

$mech->click( $button [, $x, $y] ) 
$mech->click_button( ... ) 

It is because this button does not belongs to any form and without name, I can not call or locate this button in my perl script. How can I make it possible to click this button in my perl script like I interact with browser? Thank you.

<button class="button transactional" id="checkout-now"><span>Check Out Now</span></button>

解决方案

If button does not belong to any form it should have onclick event defined, like @Bilzac and @hijack mentioned. In this case you are not able to reproduce browser's behavior because WWW::Mechanize does only html analysis.

Dealing with JavaScript events it's more easy to implement browser's network activity rather then implementing whole JavaScript events and DOM interaction.

这篇关于网站点击按钮 - Perl的WWW ::机械化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆