perl - 使用 WWW::Mechanize 为 application/x-www-form-urlencoded 发布消息
问题描述
我正在尝试向网页发布消息,但我不知道表单的名称是什么?我正在尝试 www::mechanize 但如果它是更好的方法,我会使用另一个模块。我能够拉出经过身份验证的页面并查看发布的当前消息。我在页面上转储了表格,所以这里是输出:
$VAR2 = bless( {
'default_charset' => 'UTF-8',
'enctype' => 'application/x-www-form-urlencoded',
'accept_charset' => 'UNKNOWN',
'action' => bless( do{\(my $o = 'http://myffleague.football.cbssports.com/setup/commish-tools/messaging/edit-league-message')}, 'URI::http' ),
'method' => 'POST',
'attr' => {
'style' => 'display:inline',
'method' => 'post'
},
'inputs' => [
bless( {
'readonly' => 1,
'value_name' => '',
'value' => '1',
'name' => 'dummy::form',
'id' => 'dummy::form',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
bless( {
'readonly' => 1,
'value_name' => '',
'value' => 'form',
'name' => 'form::form',
'id' => 'form::form',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
bless( {
'readonly' => 1,
'value_name' => '',
'value' => 'U2FsdGVkX1_UaI-cThHnk4dukS_AYpTgYLwzWpW7wsoYNpHOMGPSzno0W5zhDRSt',
'name' => 'form::_eid_',
'id' => 'form::_eid_',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
bless( {
'value' => '<b>Weekly High Scorers:
Week 1 => Team 12
',
'name' => 'form::message',
'class' => 'formText',
'id' => 'message',
'type' => 'textarea',
'rows' => '10',
'cols' => '60'
}, 'HTML::Form::TextInput' ),
bless( {
'readonly' => 1,
'value_name' => '',
'value' => '/setup',
'name' => 'form::xurl',
'id' => 'xurl',
'type' => 'hidden'
}, 'HTML::Form::TextInput' ),
bless( {
'value_name' => '',
'value' => ' OK ',
'name' => '_submit',
'class' => 'formButtonLg custombutton',
'type' => 'submit'
}, 'HTML::Form::SubmitInput' )
]
}, 'HTML::Form' );
我试图发布的价值是本周的高分。所以这是我正在尝试的帖子。我没有收到错误消息,但消息没有改变。对于此示例,它包含在“$msg”中
$mech->form_name('form::message');
print Dumper($mech->forms());
$mech->field("value", $msg);
$mech->submit();
在用户要求我提供更多信息后,我将添加此部分。这是我正在提取的 url,通过提供我的用户名和密码,我得到了经过身份验证的页面。那时我会使用相同的“机械”对象向联盟发布消息。
my $url = "http://myffleague.football.cbssports.com/setup/commish-tools/messaging/edit-league-message?xurl=/setup";
my $username = "username";
my $password = "password";
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_id('login_form');
$mech->field("userid", $username);
$mech->field("password", $password);
$mech->click;
my $msg = "Weekly High Scorers:\nWeek 1 => Team 12\nWeek 2 => Team 10";
$mech->field('form::message', $msg);
$mech->submit();
print "\n\nAll Good\n\n" if ($mech->success);
这是来自该站点的请求的 html。它不是整个页面,而是我需要发布的部分。我使用屏幕截图来创建图像。
解决方案
该field()
方法的第一个参数是您正在设置的字段的名称。表单中的所有字段都没有名称“值”。我认为您想要的名称是“form::message”。
$mech->field('form::message', $msg);
$mech->submit();
推荐阅读
- python - Seaborn 热图:交换 X 和 Y 轴
- sql - Sequelize - 在不同条件下两次计算相同的关联
- elasticsearch - Elasticsearch 查询(控制台) - 基于聚合计数的后过滤器
- javascript - 来自 PHP 的 Flot Chart
- c# - 在 AWS Cognito 中调用 (Admin)InitiateAuthRequest 以获取具有范围的访问令牌
- c - 理解结构
- java - Maven beans.xml
- java - 在建立数据源连接之前获取 URL 值
- zip - 将 .gz 文件添加到 .zip 存档而不解压缩和重新压缩?
- git - 在 TortoiseGit 中,哪个是 MERGE_HEAD,哪个是 HEAD?