我有那张表格
<form method="post" action="index.lp" name="authform" id="authform">
<input type="password" name="password" id="password" onkeypress="return enter_submit(event);" />
<input name="enter" class="btn btn-primary" type="button" value="log in" onclick='auth()' />我可以用这种方式提交它,谢谢javascript
javascript:document.getElementById("password").value = "password";auth();现在,我需要编写perl脚本来自动完成它,并且当它登录时,在页面中执行另一个javascript函数。我正在电脑上测试,有一些问题:
1) Perl需要一个c compiler...after,我可以在openwrt上安装它吗?
2)我可以尝试两种不同的方法:
第一个也是更快的是使用WWW::Scripter::Plugin::JavaScript,但我无法安装,因为我无法安装mingw (我在ppm-shell中安装了more,它返回了"ppm安装失败:找不到任何提供mingw的包“)。此外,我看不到Perl包中的WWW::Scripter。我写了那个脚本(它能用吗?):
use WWW::Scripter;
$w = new WWW::Scripter;
$w->use_plugin('JavaScript');
$w->get('http://url');
$w->get('javascript:document.getElementById("password").value = "password";auth();');
sleep (1);
$w->get('http://url');
$w->get('javascript: function();');第二个是使用WWW:机械化。我怎么能看到输出页面?我怎样才能向第二页发送命令呢?现在使用该脚本,我得到了一个错误:“缺少D:/Program /Perl/lib/HTTP/Response.pm第92行的基参数”。(它能用吗?)
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get( $url );
$mech->follow_link( url => 'http://url' );
$mech->submit_form(
form_name => 'authform',
fields => { password => 'password', },
button => 'log in'
);发布于 2017-11-03 12:56:45
我会使用WWW::机械化,解释依赖于DOM而没有真正的浏览器引擎的JS几乎是不可能的。
$mech->content()将从WWW::$mech->content()的上一次获取页面中获取原始的HTML。
如果您确实有需要自动化的JavaScript页面,并且希望使用perl,那么请考虑使用Selenium的WebDriver来控制“真正的”浏览器(即使它像幻影一样无头)。
至于您所得到的错误:确保您的步骤正确工作,并查看D:/Program Files/Perl/lib/HTTP/Response.pm第92行中正在发生的事情,以及它所期望的。
https://stackoverflow.com/questions/47095810
复制相似问题