stanislav5000 has asked for the wisdom of the Perl Monks concerning the following question:
Thanks!#!/usr/bin/perl use WWW::Mechanize ; #Prepopulated Information my $fname="Test"; my $lname="User"; my $address="1234 Example Street"; my $city="New York"; my $state="New York"; my $zip="10010"; my $phone="2135555555"; #Create new WWW::Mechanize object my $mech = WWW::Mechanize->new ; #Fetch URL or Die Tryin' $mech ->get("http://your.url/") ; die $mech ->res->status_line unless $mech ->success ; #Return list of forms found in the last fetched page to hand off to HT +ML::Form my @webforms = $mech->forms(); #Examine each form foreach my $form (@webforms) { my @inputfields = $form->param; #Examine each input field foreach my $inputfield (@inputfields) { if($inputfield =~ /(F|f)(irst)?name/) { $mech->set_fields( $inputfield => $fname); } if($inputfield =~ /(L|l(ast)?name/) { $mech->set_fields( $inputfield => $lname); } if($inputfield =~ /(A|a)ddress[123]?/) { $mech->set_fields( $inputfield => $address); } if($inputfield =~ /(C|c)ity//) { $mech->set_fields( $inputfield => $city); } if($inputfield =~ /(S|s)tate//) { $mech->set_fields( $inputfield => $state); } if($inputfield =~ /(Z|z)ip//) { $mech->set_fields( $inputfield => $zip); } if($inputfield =~ /(P|p)hone//) { $mech->set_fields( $inputfield => $phone); } # Submit Completed Form or Die Tryin' $mech ->submit ; die $mech ->res->status_line unless $mech ->success ; # If the form sends you somewhere, you can catch it : my $new_url = $mech ->response->request->uri->as_string ; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Submit HTML Forms with WWW:Mechanize
by Fletch (Bishop) on Mar 28, 2007 at 19:26 UTC | |
by stanislav5000 (Novice) on Mar 28, 2007 at 19:57 UTC | |
|
Re: Submit HTML Forms with WWW:Mechanize
by runrig (Abbot) on Mar 28, 2007 at 19:27 UTC | |
by stanislav5000 (Novice) on Mar 28, 2007 at 20:27 UTC | |
by runrig (Abbot) on Mar 29, 2007 at 01:14 UTC |