Results 1 to 4 of 4
I have a question about using Perl's LWP::UserAgent. I've played around with it enough to understand how to return the source code from a page but now I want to ...
- 05-22-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 31
Perl LWP::UserAgent
I have a question about using Perl's LWP::UserAgent. I've played around with it enough to understand how to return the source code from a page but now I want to learn how to actually submit form fields using Perl. I'm assuming that the differences between sites aren't tremendous besides the form's fields names. However after trying quite a few examples I still cannot get it to work. Just for trying purposes I decided to use this site
www . wheresmycellphone . com
I believe the source I'm interested in is this
And here is my current code, which isn't working.Code:<form action='submit.php' method="post"> <td> <input name="txtisdcode" type="hidden" value="1" /><h1>1</h1> </td> <td> <input name="txtcitycode" type="text" class="h1" size="3" /> </td> <td> <input name="txtphone" type="text" class="h1" size="7" maxlength="8" font="terminal" /> </td> <td><input name="submitcall" type="submit" class="h2" value="Make it Ring!"/></td> </tr>
Obviously I've changed the phone number, and also due to not being allowed to post urls yet I put spaces between the parts, but besides that this is my exact code. It appears to execute fine, but I never receive the call which I am expecting, which I do if I actually use the form on there site. Any ideas on what I am doing wrong.Code:#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common qw(POST); my $browser = LWP::UserAgent->new; my $resp = (POST 'www . wheresmycellphone . com/', ['txtisdcode' => 1, txtcitycode' => '000', 'txtphone' => '0000000']); my $response_to_discard = $browser->request($resp); print $response_to_discard;
Thanks,
John
- 05-26-2009 #2
You are actually using the "request" method incorrectly. This method takes an HTTP::Request object as an argument, not simply a list of parameters.
I would suggest using the post() method instead, and see how that works.DISTRO=Arch
Registered Linux User #388732
- 05-27-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 31
I tried changing my code to use the POST method like you said but I still cannot get it to work. Any ideas on where I'm going wrong?
Code:#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $browser = LWP::UserAgent->new; my $resp = HTTP::Request->new(POST => 'http://www.wheresmycellphone.com/'); $resp->content_type('text/html'); $resp->content('txtisdcode=1&txtcitycode=000&txtphone=000000'); print $browser->request($resp)->as_string
Thanks,
John
- 06-01-2009 #4Just Joined!
- Join Date
- Mar 2009
- Posts
- 31
I know this is somewhat an old topic, but in case anyone else looks for the solution to this problem here it is.
- JohnCode:#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $browser = LWP::UserAgent->new; my @req = ('http://www.wheresmycellphone.com/submit.php', [txtisdcode => 1, txtcitycode => '000', txtphone => '0000000', subm$ my $response_to_discard = $browser->post(@req); print $response_to_discard->as_string();


Reply With Quote