简体   繁体   English

如何通过Perl为Openwrt / LEDE提交该表单

[英]How submit that form through perl for Openwrt/LEDE

I have that form 我有那个表格

<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()' />

I can submit it thanks javascript in that way 我可以以这种方式提交感谢javascript

javascript:document.getElementById("password").value = "password";auth();

Now i need to write perl script to do it automatically and when it log in execute an other javascript function in page. 现在,我需要编写perl脚本来自动执行此操作,并在登录时执行页面中的其他javascript函数。 I'm testing it on computer and have some problem: 我正在计算机上对其进行测试,但遇到了一些问题:

1) Perl need ac compiler...after i can install it on openwrt? 1)Perl需要一个交流编译器...我可以在openwrt上安装它吗?

2) I can try 2 different ways: 2)我可以尝试2种不同的方式:

The first and more rapid is to use WWW::Scripter::Plugin::JavaScript but i cannot install the module because i cannot install mingw (i did, in ppm-shell, install mingw and it return "ppm install failed: Can't find any package that provides mingw"). 第一种更快的方法是使用WWW :: Scripter :: Plugin :: JavaScript,但由于无法安装mingw而无法安装模块(我确实在ppm-shell中安装mingw,并且返回“ ppm安装失败:可以”找不到提供mingw的任何软件包”)。 Furthermore i don't see WWW::Scripter in Perl package . 此外,我在Perl包中没有看到WWW :: Scripter。 I wrote that script (can it work?): 我写了那个脚本(可以用吗?):

  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();');

The second is to use WWW:Mechanize. 第二种是使用WWW:Mechanize。 How i can see output page? 我如何看到输出页面? And how i can send command to the second page? 以及如何将命令发送到第二页? Now with that script i get this error: "Missing base argument at D:/Program Files/Perl/lib/HTTP/Response.pm line 92.". 现在,使用该脚本我得到以下错误:“在D:/ Program Files / Perl / lib / HTTP / Response.pm第92行缺少基本参数。” (can it work?) (可以吗?)

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'
);

I'd work with WWW::Mechanize, interpreting JS that relies on the DOM without a real browser engine is close to impossible. 我将使用WWW :: Mechanize,在没有真正的浏览器引擎的情况下解释依赖DOM的JS几乎是不可能的。

$mech->content() will get you the raw HTML from WWW::Mechanize's last fetched page. $mech->content()将从WWW :: Mechanize的最后一个获取的页面获取原始HTML。

If you do have JavaScript-heavy pages that you need to automate and you want to use perl, look into using Selenium's WebDriver to control a "real" browser (even if it's headless like phantomjs). 如果确实有大量需要自动执行的JavaScript页面,并且想要使用perl,请考虑使用Selenium的WebDriver来控制“真正的”浏览器(即使它像phantomjs一样无头)。

As for the Error you are getting: make sure that your steps work correctly, and look at what's happening in D:/Program Files/Perl/lib/HTTP/Response.pm line 92, and what it does expect. 至于得到的错误,请执行以下操作:确保您的步骤正确运行,并查看D:/Program Files/Perl/lib/HTTP/Response.pm第92行中发生的情况以及预期的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM