develooper Front page | perl.libwww | Postings from April 2001

Problems submitting form with form->click (repost)

Thread Next
Steve Borruso
April 6, 2001 13:20
Problems submitting form with form->click (repost)
Message ID:

I've reposting this request with my script included  along with debug
output. Any assistance is appreciated.

Having difficulty submitting a form and capturing the resulting page.
Nothing is returned when I try form->click.
My script is included below and so far will -

Log in to a remote site with my userid/pwd (with cookies and
redirection). Successfully request a page that's full of pre filled
form data.

I now need to -

1) Alter/add data to one particular text area (should be able to
    just  parse the received content, insert my data, then paste it
    back together)

2) Need to then click the Submit button on this form, that has
    my change. Don't want to handle it by specifying name/value
    pairs as the form may change in the future.

3) Once this altered form is submitted I need to catch the resulting
   page, which is another form, and click the Submit button on that

Included output from a $form->dump below, followed by output from
$form->form for the form I'm trying to submit.
The second output doesn't show the "submit" input controls.
Gave up on trying to use LWP::Debug, couldn't get it to generate any

Can't get the $form->click to work,  tried variations like ...
$r = $ua->simple_request($form->click($name)) ;
$r = $ua->simple_request($form->click) ;

$ua is used earlier on and defined as -

   my $ua = LWP::UserAgent->new;
   $ua->cookie_jar(HTTP::Cookies->new(file => "$CustCookieFile",
autosave => 1));

Was going to try $form->make_request but figured since click() calls
this it wasn't worth trying.

Any assistance is most appreciated.

Output from $form->dump

POST itemnum=
2219950 (hidden) login=xxx(hidden) password=xxxx
(hidden) title= 2 just testing BV please don't bid
bold_title=(checkbox) [*|1] banner_line= banner=
(checkbox) [*|1] Category1=134 CatMenu_0=---------
-------------------------- (option) [*------------
------------------- (option) [*-------------------
------------ (option) [*--------------------------
---------]quantity=1 description=testing again (
textarea) minimum_bid=1.00 reserve_bid=0.00increment
_valu=.2500 (hidden) take_it_price=picture=http://xxx. place1=2 (radio) [*2|1]
sound=http:// place2=2 (radio) [*2|1] gallery=0
(radio) [*0|1|2] already_in_gallery=0 (hidden)counter=
(checkbox) [*|1] featured=0 (hidden) featured_cat=
(checkbox) [*|1] auto_relist=5 date_end=2001-04-09
21:50:00 (hidden) date_start=2001-03-20 21:50:00
(hidden)duration=20 (hidden) shipping= (hidden)
payment= (hidden) submit=Add Item (submit) = (reset)

Output from $form->form (some fields were added since I

itemnum2219950loginxxxpasswordxxxtitle 2 just testing
BV please don't bid banner_lineCategory1134CatMenu_0-----
list5date_end2001-04-0921:50:00date_start2001-03-20 21:50:

Here's my script ....

use LWP::Simple ;
use HTML::TokeParser;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;
use HTML::Form;


# First login with userid/pwd handling cookies and re-direction
# This all works fine ...
$CookieFile = '/mycookiefile.tx';
my $ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "$CookieFile", autosave =>
my $r = $ua->simple_request(POST "",
         url => '',
         nickname => "$myuserid"',
         password => '$mypass",
while ($r->is_redirect) {
  my $u = $r->header('location') or die "missing location: ",
  print "redirecting to $u\n";
  $r = $ua->simple_request(GET $u);
# Now request the page that contains pre-filled in form data
$Form_1_Page =
'' .
$bidville_logo_items[$i] ;
$res = $ua->request(HTTP::Request->new(GET => "$Form_1_Page"));
$html = $res->content;

print $html ;

# Everything works fine up to this point
# Should be able to parse $html here, inserting my change into proper
text box

# Now need to submit the altered form and capture the resulting page

$form = HTML::Form->parse($html,'');
$r = $ua->simple_request($form->click());

print $form->dump;
print '<p>';
print $form->form;

print $r-> as_string;
$html2 = $r->content;
print $html2;


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About