Google Answers Logo
View Question
 
Q: perl: fetch page with form, then simulate its submission ( No Answer,   0 Comments )
Question  
Subject: perl: fetch page with form, then simulate its submission
Category: Computers > Software
Asked by: marcfest-ga
List Price: $25.00
Posted: 11 Sep 2005 11:04 PDT
Expires: 11 Oct 2005 11:04 PDT
Question ID: 566824
Hello - I need a little perl script that will retrieve a Web page
containing a form, and then will submit the as if a user had retrieved
the page in a browser and then clicked the submit button.

As an answer to this question, please devise a script that will fetch
a page specified in $url and then submit the form in it, assuming that
there is a submit button with the name attribute "submitbutton" and
with a value attribute of "submit".

Thank you.

Marc.

Request for Question Clarification by palitoy-ga on 11 Sep 2005 12:15 PDT
Hello Marc

Thank-you for your question.

I am a little confused as to why you would require to download the
page with the form on first. You can process the form directly in Perl
by just passing the variables directly to the form processing page
(the page in the form access attribute) in you know the form pairs you
need to fill out.  The form pairs are easy to find if you simply
invesigate the HTML <form> tag.

If you simply download the form from a webpage and then immediately
submit it (as your question suggests) you will submit the form without
adding any values to the form fields.  You would normally fill these
in as a user.

Here is a simple example of submitting a form using GET:

###################################################
use URI;
use LWP::UserAgent;
# define your url
my $url;
$url = URI->new( $url );
# build query
$url->query_form(
  # the form pairs - fill these in with the values from the form in the url
  'submitbutton' => 'submit',
  'value1' => 'value'
);
# get the form
my $response = LWP::UserAgent->new->get( $url );
# print out the results
print $response->content;
###################################################

A similar solution can be easily built for a form that needs to use POST.

Let me know if this is sufficient for an answer and I will provide the
POST solution also.

palitoy-ga
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy