我使用 LWP 和 HTTP::Request::Form 填写表单时遇到什么问题?

发布于 2024-11-27 11:15:15 字数 457 浏览 2 评论 0原文

我是 Perl 新手,目前正在编写一个 Perl 脚本来自动填写 Web 表单并使用 LWP 提交它们。网站 URL 是 ***/something.cgi ,在该文档中有一个我需要填写的表格,然后点击提交。这将我带到另一个页面,其中有另一个表格需要填写,但网站的 URL 保持不变。

我设法填写第一个表单并使用以下方式提交:

$res = $ua->request($f->press("submit"));

其中

my $f = HTTP::Request::Form->new($forms[0], $url);

查看 $res->as_string 显示下一页源代码,但尝试获取新表单以填写它,但它给了我我已经有了同样的表格。我如何才能进入下一页以填写表格并继续?

I'm new to Perl, currently writing a Perl script to automatically fill web forms and submit them using LWP. The website URL is ***/something.cgi and in that document there is a form I need to fill, then hit submit. That takes me to another page which has another form to fill, but the website's URL remains the same.

I managed to fill the first form and submit it using:

$res = $ua->request($f->press("submit"));

where

my $f = HTTP::Request::Form->new($forms[0], $url);

Viewing $res->as_string shows the next page source, but tried to get the new forms in order to fill it, but it gave me the same form I already have. How can I get next page in order to fill its forms and proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紧拥背影 2024-12-04 11:15:15

我建议您查看 WWW::Mechanize 及其 表单方法,它是 LWP::UserAgent

编辑

添加一个与我的第一个链接中的示例密切相关的示例:

use strict;
use warnings;

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

$mech->get( 'http://google.com' );
sleep 1; ## be nice

$mech->submit_form(
    form_number => 0,
    fields      => {
        q       => 'mungo',
    }
);

print $mech->content;

I would recommend you look at WWW::Mechanize and its form methods which is a subclass of LWP::UserAgent.

EDIT

Adding an example closely based on the example from my first link:

use strict;
use warnings;

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

$mech->get( 'http://google.com' );
sleep 1; ## be nice

$mech->submit_form(
    form_number => 0,
    fields      => {
        q       => 'mungo',
    }
);

print $mech->content;
时光是把杀猪刀 2024-12-04 11:15:15

您尝试编写脚本的表单必须使用某些参数或 cookie 来确定要处理多页表单中的哪一页。查看返回的cookie,

print $res->header();

看看是否有为会话ID或您需要传回的其他参数设置的cookie。

另外,查看第一个表单页面与第二个表单页面的源代码,看看是否有隐藏指示第二次提交针对第二个表单页面的输入类型。或者,查看提交按钮标记的值,也许第二页上的值不同。

The form you are trying to script must be using some paramter or cookie to determine which page of the multi-page form to process. Look at the cookies returned in

print $res->header();

to see if there are cookies being set for a session-ID or other parameter that you need to pass back in.

Also, look at the source of the first form page vs the second, see if there are hidden input types that indicate that the second submission is for the second form page. Or, look at the value of the submit button tag, maybe that is different on the second page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文