gpt4 book ai didi

perl - 如何使用 WWW::Mechanize 和下拉菜单在 Perl 中导航网页?

转载 作者:行者123 更新时间:2023-12-01 16:47:56 25 4
gpt4 key购买 nike

我有一个问题,我正在尝试做的是:

我用 WWW::Mechanize 打开一个网页,填写用户名和密码并登录。

我遇到的问题是,登录后我必须从下拉列表中选择值然后我必须按提交。

我该怎么做?

我使用的代码是:

#!/usr/bin/perl
use LWP::UserAgent;
use WWW::Mechanize;
use HTTP::Cookies;
use strict;

my $username="123456";
my $password="XXXXX";
my $project="Systems";
my $agent = WWW::Mechanize->new();
$agent->get('http://www.XXXXX.com');
$agent->form_name("login_form");
$agent->field("txtLoginId", $username);
$agent->field("txtPassword", $password);
$agent->submit();
#Till now it has success full logined, From here it has to select one value from a drop #down box
$agent->form_name("frmProject");
$agent->field("cboProject", $project);
my $response=$agent->submit();

if ($response->is_success){
print "\nContent:\n";
print $response->as_string;
}elsif ($response->is_error){
print $response->error_as_HTML;
}

最佳答案

WWW::Mechanize 有一个click 方法,您可以使用它来单击按钮。或者,研究 submit_form 方法,您可以为其指定所有表单元素的值。如果该页面使用 javascript,WWW:Mechanize 可能不适合您的任务(例如参见 WWW::Mechanize::Firefox 作为替代)。

关于perl - 如何使用 WWW::Mechanize 和下拉菜单在 Perl 中导航网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12500095/

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