Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Can anyone help me please? I am trying to simulate form submission. This is what I have tried. But the form->click() function does not seem to submit the form. When I try to download a page after that, it still downloads the page that says that I need to submit siteid, username and password.

Thanks.

#!/usr/bin/perl use HTTP::Cookies; use HTML::Form; use LWP; use URI; require 'dumpvar.pl'; my $sId = 'siteID'; my $log = 'username'; my $pswd = 'password'; my $ua = LWP::UserAgent->new(); my $url = 'http://xxx.yyy.html'; my $login_req = HTTP::Request->new(GET => $url); my $login_res = $ua->request($login_req); my $html = $login_res->content; my $form = HTML::Form->parse($html, "http://xxx.yyy.html"); #dumpValue(\$form); $form->value('site', $sId); $form->value('user', $log); $form->value('pass', $pswd); $form->click; $url = 'http://xxx.yyy.html'; $login_req = HTTP::Request->new(GET => $url); $login_res = $ua->request($login_req); print $login_res->content;

Edited 2001-10-18 by Ovid

Replies are listed 'Best First'.
Re: Problem with automated form submission
by tomhukins (Curate) on Oct 19, 2001 at 00:04 UTC

    Remeber that HTTP is a stateless protocol, so no two requests are related to each other.

    There are several ways of getting around this, and it's hard to know which one the site you are using deploys, since you've hidden its name from us by calling it xxx.yyy.html. This makes it hard for us to solve your problem.

    It's likely, though, that when the form is submitted, the site returns a cookie. Your HTTP::Request doesn't send any cookie. After you've done $form->click, you'll need to check the response to find out if any cookies have been set, and then send them with any future requests.

      Sorry, the site is http://mi.compustat.com/auth/MI_login Yes it does use cookies. But I really cannot figure out how to get/set cookies. Any suggestions please? Thanks again.

        Take a look at the documentation for HTML::Form, specifically the make_request method, which you can use instead of click.

        make_request returns an HTTP::Request object, which you can retrieve the cookies from using HTTP::Cookies module. There's a good summary of how to do this in the lwpcook document that comes with libwww-perl.