gpt4 book ai didi

javascript - 如何通过 Openwrt/LEDE 的 perl 提交该表单

转载 作者:行者123 更新时间:2023-11-28 04:01:11 24 4
gpt4 key购买 nike

我有那个表格

<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 编译器...我可以在 openwrt 上安装它吗?

2)我可以尝试两种不同的方法:

第一个也是更快的是使用 WWW::Scripter::Plugin::JavaScript 但我无法安装该模块,因为我无法安装 mingw (我在 ppm-shell 中安装了 mingw它返回“ppm 安装失败:找不到任何提供 mingw 的包”)。此外,我在 Perl package 中没有看到 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:Mechanize。我如何才能看到输出页面?我如何将命令发送到第二页?现在使用该脚本我收到此错误:“D:/Program Files/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'
);

最佳答案

我会使用 WWW::Mechanize,在没有真正的浏览器引擎的情况下解释依赖于 DOM 的 JS 几乎是不可能的。

$mech->content() 将从 WWW::Mechanize 最后获取的页面获取原始 HTML。

如果您确实有大量 JavaScript 页面需要自动化,并且想要使用 Perl,请考虑使用 Selenium 的 WebDriver 来控制“真正的”浏览器(即使它像 phantomjs 一样是 headless 的)。

至于您遇到的错误:确保您的步骤正确运行,并查看 D:/Program Files/Perl/lib/HTTP/Response.pm 第 92 行中发生的情况,以及它的期望。

关于javascript - 如何通过 Openwrt/LEDE 的 perl 提交该表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47095810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com