gpt4 book ai didi

ajax - 如何使用 WWW::Mechanize (ajax) 发布表单

转载 作者:行者123 更新时间:2023-12-04 16:19:08 25 4
gpt4 key购买 nike

几天前我发布了关于通过更改页面大小发布表单的信息。有人可以帮忙看看步骤。我包括表单的转储和我用来发布它的代码。这是获取第一页的代码,默认为 30 个播放器的页面大小,然后我将发布表单以将页面大小更改为 500。

my $mech = WWW::Mechanize->new();
my $url = "https://www.fangraphs.com/projections.aspx?pos=all&stats=bat&type=steamer&team=0&lg=all&players=0";
$mech->get($url);
print Dumper($mech->forms());
$VAR1 = bless( {
'default_charset' => 'UTF-8',
'enctype' => 'application/x-www-form-urlencoded',
'accept_charset' => 'UNKNOWN',
'action' => bless( do{\(my $o = 'https://www.fangraphs.com/projections.aspx?pos=all&stats=bat&type=steamer&team=0&lg=all&players=0')}, 'URI::https' ),
'method' => 'POST',
'attr' => {
'id' => 'form1',
'method' => 'post'
},
'inputs' => [
bless( {
'readonly' => 1,
'/' => '/',
'value_name' => '',
'value' => '',
'name' => 'RadScriptManager1_TSM',
'id' => 'RadScriptManager1_TSM',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
bless( {
'/' => '/',
'value' => '30',
'name' => 'ProjectionBoard1$dg1$ctl00$ctl02$ctl00$PageSizeComboBox',
'readonly' => 'readonly',
'value_name' => '',
'type' => 'text',
'class' => 'rcbInput radPreventDecorate',
'id' => 'ProjectionBoard1_dg1_ctl00_ctl02_ctl00_PageSizeComboBox_Input'
}, 'HTML::Form::TextInput' ),
bless( {
'tabindex' => '-1',
'class' => 'rcbActionButton',
'type' => 'button'
}, 'HTML::Form::SubmitInput' ),
bless( {
'readonly' => 1,
'/' => '/',
'value_name' => '',
'name' => 'ProjectionBoard1_dg1_ctl00_ctl03_ctl01_PageSizeComboBox_ClientState',
'id' => 'ProjectionBoard1_dg1_ctl00_ctl03_ctl01_PageSizeComboBox_ClientState',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
]
}, 'HTML::Form' );


然后我尝试使用以下内容提交表单:
$mech->submit_form(
form_id => 'form1',
with_fields => {
name => 'ProjectionBoard1$dg1$ctl00$ctl03$ctl01$PageSizeComboBox',
id => 'ProjectionBoard1_dg1_ctl00_ctl03_ctl01_PageSizeComboBox_Input',
value => 500,
},
);

但我从脚本中得到的响应是“没有包含请求字段的表单”

最佳答案

尝试这样的事情:

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url = "https://www.fangraphs.com/projections.aspx?pos=all&stats=bat&type=steamer&team=0&lg=all&players=0";
$mech->get($url);
$mech->set_fields(
'RadScriptManager1_TSM' => '',
'ProjectionBoard1$dg1$ctl00$ctl02$ctl00$PageSizeComboBox' => '30'
'ProjectionBoard1_dg1_ctl00_ctl03_ctl01_PageSizeComboBox_ClientState' => ''
);
$mech->submit;

使用语法 'FIELD_NAME' => 'VALUE' 设置表单字段,然后提交

关于ajax - 如何使用 WWW::Mechanize (ajax) 发布表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60400930/

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