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

Problems submitting form with form->click (repost)

Thread Next
From:
Steve Borruso
Date:
April 6, 2001 13:20
Subject:
Problems submitting form with form->click (repost)
Message ID:
3ACE2503.8F24F548@stny.rr.com
Greetings,

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
   page.


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
output.

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

$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.
Steve


Output from $form->dump

POST http://www.bidville.com/edit_info.cfm 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) [*------------
-----------------------]CatMenu_1=----------------
------------------- (option) [*-------------------
----------------]CatMenu_2=-----------------------
------------ (option) [*--------------------------
---------]quantity=1 description=testing again (
textarea) minimum_bid=1.00 reserve_bid=0.00increment
_valu=.2500 (hidden) take_it_price=picture=http://xxx.
xxx.com/backgrounds/sequins.jpg 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-----
------------------------------CatMenu_1------------------
-----------------CatMenu_2--------------------------------
---quantity1descriptiontestingagainminimum_bid1.00reserve_
bid0.00increment_valu.2500take_it_pricepicturehttp://xxxl
xxx.xxxxxxx.com/backgrounds/sequins.jpgplace12sound
http://place22gallery0already_in_gallery0featured0auto_re
list5date_end2001-04-0921:50:00date_start2001-03-20 21:50:
00duration20shippingpayment

Here's my script ....

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

etc..........

#-----------------------------------------------------------
# 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 =>
1));
my $r = $ua->simple_request(POST "http://www.bidville.com/login.cfm",
        {
         url => '',
         nickname => "$myuserid"',
         password => '$mypass",
         });
while ($r->is_redirect) {
  my $u = $r->header('location') or die "missing location: ",
$r->as_string;
  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 =
'http://www.bidville.com/personal/edit_info.cfm?submit=Edit&itemnum=' .
$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,'http://www.bidville.com');
$r = $ua->simple_request($form->click());

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

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

exit;





Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About