【问题标题】:How to post form with WWW::Mechanize (ajax)如何使用 WWW::Mechanize (ajax) 发布表单
【发布时间】:2020-02-25 18:20:02
【问题描述】:

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

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

【问题讨论】:

  • 它应该是with_fields => { $field_name => $field_value } 但是它试图设置``readonly 文件(它不会产生你想要的东西)。
  • 字段名称和id与你get req收到的表单的名称和id不匹配。

标签: ajax perl mechanize


【解决方案1】:

试试这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-16
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-21
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多