initself has asked for the wisdom of the Perl Monks concerning the following question:
The following is an attempt to use LWP to populate a form. I want to fill out the form, press submit, and see the result.
Update: Turns out I was not properly submitting the form with HTML::Form. See Corion's reply for details.
When I submit this form, the result I get back in my UserAgent is not what I expect. Instead of a page showing the results based on my form fields, what I get back is the default page again. Because there Javascript embedded into the page I am browsing in my script, which HTML::Form cannot interact with, I tried emulating the Javascript in my code.
Any warnings you see if you try to run the code are harmless per the HTML::Form docs. Naturally a hidden field set to read-only will give a warning when it is populated.
Can anyone see how I need to setup this form for the server to accept my post? Where are some likely places that might have issues in the code?
Here's the code:
#!/usr/bin/perl # browse.pl use strict; use warnings; use CGI ':standard'; use LWP::UserAgent; use HTML::Form; use Data::Dumper; my $browser = LWP::UserAgent->new; my $browse_url = 'http://browseusers.myspace.com/Browse/Browse.aspx'; my $response = $browser->get($browse_url); my @forms = HTML::Form->parse($response); # Pull ACTION out of JavaScript function, replace in FORM element my $content = $response->content; $content =~ m{document\.frmBrowse\.action = "(.*?)"}; my $action_url = "http://browseusers.myspace.com/Browse/" . "$1"; $forms[1]->action($action_url); my $action = $forms[1]->action; # Get Form Elements my $zipRadius = $forms[1]->find_input("zipRadius", "option"); my $zipCode = $forms[1]->find_input("zipCode", "text"); my $Scope = $forms[1]->find_input("Scope", "radio"); # Get Hidden Elements my $__EVENTTARGET = $forms[1]->find_input("__EVENTTARGET"); my $Page = $forms[1]->find_input("Page"); # Assign Values $zipRadius->value("5"); $zipCode->value("92630"); #$Scope->value("scopeMyFriends"); #Populate Hidden Elements (WARNINGS OK) $__EVENTTARGET->value("update"); $Page->value("1"); # Update Form $forms[1]->click("update"); # Get Response from Server $content = $response->content; print $content; # Dump Form (For Testing Only) #print $forms[1]->dump;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Form Submit Issue
by Corion (Patriarch) on Dec 09, 2005 at 07:36 UTC | |
by initself (Monk) on Dec 09, 2005 at 08:42 UTC |