Click here to get back home

HTTP::Request::Form - Problem pressing input type=image button

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
HTTP::Request::Form - Problem pressing input type=image button fochie 02-01-2005
Get Chitika Premium
Posted by fochie on February 1, 2005, 7:56 am
Please log in for more thread options
Greetings,

Posted a question here last night which seems to have disapeared, sorry
if this shows up as a dupe.

I'm having difficulty "pressing" a form button that is type=image using
HTTP::Request::Form with HTTP::TreeBuilder. I can obtain the form page,
parse data and fill in text input areas fine. The object on the page to
submit the form is type=image and I'm confused on the syntax of
specifying this using the press method. All attempts result in the
indication that the button does not exist in the form.

A dump of the form from my perl script shows the following after
filling in the seller field -

FORM METHOD=POST
ACTION=/exec/varzea/ae-nickname-search/

BASE=http://s1.amazon.com/exec/varzea/subst/search/auction-search.html/ref=a_h_tn_as/104-8399919-2455160
FIELD exchange-type=auction
FIELD seller=mysellerid
BUTTON image=[image]
image=

The HTTP::Request::Form doc states the following related
to pressing a button of type=image -

press([$name [, $coord ] [, $number]])
....
The "coord" parameter comes in handy if you have an image button. If
this is the case, the button press will simulate a press at coordinates
[2,2] unless you provide an anonymous array with different coordinates.
.... "

Not sure how to correctly specify the button on this method without
using a name parameter.
Any assistance is most appreciated.

Thanks,
Steve



Posted by fochie on February 1, 2005, 1:06 pm
Please log in for more thread options
I've been able to press the image button and get a response back IF I
do not fill in the seller input field.

If I do not supply input to the field, I get an HTML page back stating
that the input to the field is missing (some progress anyway ;-).

If I supply input to the seller field ( $f->field("seller",
"mysellerid");)
nothing at all prints when I print the response from the request.

I've attached my test script and sample output below for the case where
the seller input field is not supplied.

Any assistance is appreciated.... Thanks !

#!/usr/bin/perl -w
use URI::URL;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use HTTP::Request::Form;
use HTML::TreeBuilder 3.0;

$advanced_search_page_url =
'http://s1.amazon.com/exec/varzea/subst/search/auction-search.html/ref=a_h_tn_as/104-8399919-2455160';

my $ua = LWP::UserAgent->new;

my $url = url $advanced_search_page_url;
my $res = $ua->request(GET $url);

my $tree = HTML::TreeBuilder->new;
$tree->parse($res->content);
$tree->eof();

#print $tree->dump;

my @forms = $tree->find_by_tag_name('FORM');
die "No forms in $url?" unless @forms;

my $f = HTTP::Request::Form->new($forms[1], $url);

##### $f->field("seller", "mysellerid");

@mybuttons = $f->buttons();

print "here are the buttons @mybuttons" . "n";

print $f->dump();

my $response = $ua->request($f->press($mybuttons[0]));
print $response->content ;#if $response->is_success;

exit;

Sample output -


-bash-2.05b$ perl Amazon_trees.pl
here are the buttons image
FORM METHOD=POST
ACTION=/exec/varzea/ae-nickname-search/

BASE=http://s1.amazon.com/exec/varzea/subst/search/auction-search.html/ref=a_h_tn_as/104-8399919-2455160
FIELD exchange-type=auction
FIELD seller=mysellerid
BUTTON image=[image]
image=



Posted by fochie on February 1, 2005, 1:06 pm
Please log in for more thread options
I've been able to press the image button and get a response back IF I
do not fill in the seller input field.

If I do not supply input to the field, I get an HTML page back stating
that the input to the field is missing (some progress anyway ;-).

If I supply input to the seller field ( $f->field("seller",
"mysellerid");)
nothing at all prints when I print the response from the request.

I've attached my test script and sample output below for the case where
the seller input field is not supplied.

Any assistance is appreciated.... Thanks !

#!/usr/bin/perl -w
use URI::URL;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use HTTP::Request::Form;
use HTML::TreeBuilder 3.0;

$advanced_search_page_url =
'http://s1.amazon.com/exec/varzea/subst/search/auction-search.html/ref=a_h_tn_as/104-8399919-2455160';

my $ua = LWP::UserAgent->new;

my $url = url $advanced_search_page_url;
my $res = $ua->request(GET $url);

my $tree = HTML::TreeBuilder->new;
$tree->parse($res->content);
$tree->eof();

#print $tree->dump;

my @forms = $tree->find_by_tag_name('FORM');
die "No forms in $url?" unless @forms;

my $f = HTTP::Request::Form->new($forms[1], $url);

##### $f->field("seller", "mysellerid");

@mybuttons = $f->buttons();

print "here are the buttons @mybuttons" . "n";

print $f->dump();

my $response = $ua->request($f->press($mybuttons[0]));
print $response->content ;#if $response->is_success;

exit;

Sample output -


-bash-2.05b$ perl Amazon_trees.pl
here are the buttons image
FORM METHOD=POST
ACTION=/exec/varzea/ae-nickname-search/

BASE=http://s1.amazon.com/exec/varzea/subst/search/auction-search.html/ref=a_h_tn_as/104-8399919-2455160
FIELD exchange-type=auction
FIELD seller=mysellerid
BUTTON image=[image]
image=



Posted by fochie on February 1, 2005, 2:23 pm
Please log in for more thread options
More thoughts ... after "refering" back to my trusty Perl & LWP book
....

I thought that since nothing is being returned by the request on the
"press" method that maybe I needed to set the referer value for the
request. I issued the following prior to the press request -

$myreferer = $f->referer();
print "referer is $myreferer " ."n";
$f->referer($myreferer);

This did not help, same indication, nothing bak from the request.

I flipped the debug bit on in the form parser -
my $f = HTTP::Request::Form->new($forms[1], $url, 1);

and it produced this -


1POST http://s1.amazon.com/exec/varzea/ae-nickname-search/
exchange-type - auction - seller - mysellerid - image.x - 2 - image.y -
2

So it look like the request should go out I guess... just confused on
why I don't get a response.



Posted by fochie on February 1, 2005, 2:57 pm
Please log in for more thread options
Solved my problem .... LWP & Perl book to the rescue once again ....
decided to look in the returned headers .... the url for the page I
need was in the Location header containing the token for the sellerid
that I now need to continue crawling forward.



Similar ThreadsPosted
HTTP::Mechanize / file-form October 13, 2006, 10:16 pm
http request headers October 1, 2004, 12:47 pm
Help regarding HTTP::Request:POST February 24, 2006, 11:31 pm
HTTP::Request::Common::POST and UTF-8 September 27, 2005, 12:21 pm
troubles with HTTP::Request::Common March 8, 2005, 11:42 pm
How can I make HTTP::Request handle gzipped content? September 3, 2004, 2:11 am
Parse tcpdump for HTTP Request Response Headers July 29, 2007, 2:10 pm
Net::Analysis Parse tcpdump for HTTP Request/Response Headers July 29, 2007, 6:41 am
reading from Net::Telnet input string problem June 16, 2006, 1:17 pm
XML::Twig parseurl with input Headers/XML January 16, 2005, 10:58 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap