Too vague? Nonesense!

I'm trying to simulate the action of clicking the "Submit" button

Simple: use LWP::Simple

say you have a CGI script like this (called foo.cgi):

#!/usr/bin/perl use strict; use CGI; my $cgi = new CGI; print $cgi->header; if (my $foo = $cgi->param('foo')) { print "foo = $foo"; } else { print "nothing special"; }
all this script does is check for a parameter named 'foo' - if found, print it's value, otherwise print some default message.

If you create an HTML document that contains a form that points to this script, and include a text box named 'foo' and a submit button - then when the user clicks the submit button, the value of 'foo' is sent to the script.

So, to automate this behaviour in a Perl script, you can either roll out your own socket code, or be cool and use the LWP::Simple CPAN module - which by the way, is not the only module for such a purpose (check out LWP::UserAgent for more advanced control).

Here is the simple web bot:

#!/usr/bin/perl -w use strict; use LWP::Simple; print "with no arguments: "; print get('http://localhost/cgi-bin/foo.cgi'), "\n"; print "with arguments: "; print get('http://localhost/cgi-bin/foo.cgi?foo=bar'), "\n";
And that's it.

Jeff

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: Help with forms by jeffa
in thread Help with forms by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.