FAQ 9.9 How do I automate an HTML form submission?

Discussion in 'Perl Misc' started by PerlFAQ Server, Mar 16, 2011.

  1. This is an excerpt from the latest version perlfaq9.pod, which
    comes with the standard Perl distribution. These postings aim to
    reduce the number of repeated questions as well as allow the community
    to review and update the answers. The latest version of the complete
    perlfaq is at http://faq.perl.org .

    --------------------------------------------------------------------

    9.9: How do I automate an HTML form submission?

    If you are doing something complex, such as moving through many pages
    and forms or a web site, you can use "WWW::Mechanize". See its
    documentation for all the details.

    If you're submitting values using the GET method, create a URL and
    encode the form using the "query_form" method:

    use LWP::Simple;
    use URI::URL;

    my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
    $url->query_form(module => 'DB_File', readme => 1);
    $content = get($url);

    If you're using the POST method, create your own user agent and encode
    the content appropriately.

    use HTTP::Request::Common qw(POST);
    use LWP::UserAgent;

    $ua = LWP::UserAgent->new();
    my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
    [ module => 'DB_File', readme => 1 ];
    $content = $ua->request($req)->as_string;



    --------------------------------------------------------------------

    The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
    are not necessarily experts in every domain where Perl might show up,
    so please include as much information as possible and relevant in any
    corrections. The perlfaq-workers also don't have access to every
    operating system or platform, so please include relevant details for
    corrections to examples that do not work on particular platforms.
    Working code is greatly appreciated.

    If you'd like to help maintain the perlfaq, see the details in
    perlfaq.pod.
    PerlFAQ Server, Mar 16, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon Shaw

    (onetime) Form Submission

    Leon Shaw, Aug 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    355
  2. Replies:
    0
    Views:
    472
  3. Simon Jackson

    can ruby automate form submission?

    Simon Jackson, Feb 23, 2007, in forum: Ruby
    Replies:
    2
    Views:
    184
    Simon Jackson
    Feb 23, 2007
  4. Jared
    Replies:
    5
    Views:
    209
    Jared
    Jul 10, 2003
  5. patrick73

    HTML form submission via XMLHttpRequest

    patrick73, Jul 13, 2006, in forum: Javascript
    Replies:
    2
    Views:
    111
    patrick73
    Jul 13, 2006
Loading...

Share This Page