Reputation: 203
I'm trying to post a message to a webpage but I can't figure out what the name of the form is? I am trying www::mechanize but I would use another module if its a better method. I am able to pull the authenticated page and see the current message posted. I dumped the forms on the page so here is the output:
$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' );
The value I'm trying to post is the high scorer of the week. So here is the post I'm attempting. I don't get an error, but the message doesn't change. For this example its contained in '$msg'
$mech->form_name('form::message');
print Dumper($mech->forms());
$mech->field("value", $msg);
$mech->submit();
I'm adding this section after users requested more information from me. this is the url i'm pulling, by supplying my userid and password I get the authenticated page back. At that point I then use the same 'mech' object to post a message to the league.
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);
And here is the requested html from the site. Its not the entire page, but the section where I need to post. I used screenshot to create the image.
Upvotes: 0
Views: 204
Reputation: 69244
The first parameter to the field()
method is the name of the field you're setting. None of the fields in your form has the name "value". I think the name that you want is "form::message".
$mech->field('form::message', $msg);
$mech->submit();
Upvotes: 1