Beau Landeaux has asked for the wisdom of the Perl Monks concerning the following question:

Brothers, This is probably a really dumb question but since I have considerably more experience with ignorance than wisdom, there's really no risk in asking another. Is there a way in Perl to actually press (simulate pressing) the "submit" button? Using LWP, I can easily fill in the fields on the form, but then I need to submit tha data as though I clicked on the submit button. Any ideas or is this a REALLY DUMB QUESTION? Brother Beau

Replies are listed 'Best First'.
Re: Submit Button
by kabel (Chaplain) on Sep 26, 2002 at 03:43 UTC
    note: there is no silly question, only silly answers (free translation of a german saying)

    i hope you can cope with it:
    use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $proxy = 'http://myproxi:8080'; my $key1 = 'Feldname1'; my $val1 = 'Feldwert1'; my $key2 = 'Feldname2'; my $val2 = 'Feldwert2'; my $key3 = 'Feldname3'; my $val3 = 'Feldwert3'; # usw my $url = 'http://www.domain.tld'; my $ua = LWP::UserAgent->new(); $ua->proxy(['http','ftp'], $proxy) if $proxy; my $re = POST $url, [$key1=>$val1,$key2=>$val2,$key3=>$val3]; my $page = $ua->request($re)->as_string; print $page;
Re: Submit Button
by chromatic (Archbishop) on Sep 26, 2002 at 05:51 UTC

    Treat the name and value of the appropriate submit button as just another form field.

      Hi chromatic,

      I _can't_believe_ I have never thought of that :-) . I am already saving time by using this technique.
      Good question Beau Landeaux.

      cheers

      thinker
Re: Submit Button
by Helter (Chaplain) on Sep 26, 2002 at 13:05 UTC
    I am writing some code that reads the forms and processes the information on the fly. I've found that using HTML::Form works really well for me. This is the form that has radio buttons, and drop-down menus and a single submit button
    @requestForms = HTML::Form->parse( $response->content, $response->base + ); #Multiple forms on the page, The first one is always ignored $requestForms[1]->value('radiobutton' => 'name of radio button I want +selected'); @options = $requestForms[1]->find_input('name of drop-down menu')->pos +sible_values(); #Select the first item in the list $requestForms[1]->value( 'name of drop-down menu' => $options[1] ); #There is always only 1 button, if there are more than 1 then put the +name as an argument to click. $response = $userAgent->request($requestForms[1]->click( ));
    Hope this helps!
Re: Submit Button
by adrianh (Chancellor) on Sep 26, 2002 at 21:21 UTC

    You might also want to take a look at WWW::Mechanize for doing this sort of thing.