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

问题描述 投票:1回答:1

我几天前发布了有关通过更改页面大小来发布表单的信息。有人可以帮忙吗?我包括了表单的转储以及用于发布它的代码。这是获取第一页的代码,该页的默认页面大小为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,
    },
);

但是我从脚本中得到的响应是'没有包含所要求字段的表格'

ajax perl mechanize
1个回答
0
投票

尝试类似的事情:

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'设置表单字段,然后提交

© www.soinside.com 2019 - 2024. All rights reserved.