CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Using Perl to interface with web pages

 



jim_lad
Novice

Jul 6, 2006, 9:02 AM

Post #1 of 5 (503 views)
Using Perl to interface with web pages Can't Post

Hi there,

First post in this forum, hopefully I've got the right one...

Basically I'm after some pointers. I've been using perl for about a year but what I'm trying to do at the moment is something I haven't dealt with before.

I'm attempting to write a script which will read in variables from a text file (I've no problem with this part) and then enter this data into a form on a website, send the form and pull a specific piece of data from the resulting table.

I've written cgi scripts before so I'm familiar (if a little rusty!) with the get and post methods, however I believe I need to use the LWP family of modules.

I've tried reading the CPAN literature on the modules but didn't find it all that helpful.

Can someone give me some pointers or have any links to good tutorials on the subject.

Thanks,
Jamie.


davorg
Thaumaturge / Moderator

Jul 7, 2006, 5:56 AM

Post #2 of 5 (497 views)
Re: [jim_lad] Using Perl to interface with web pages [In reply to] Can't Post

You're on the right lines with LWP, but you should also look at WWW::Mechanise - which is a wrapper around LWP which makes it easier to use.

If you have any specific questions then please feel free to post them here.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


jim_lad
Novice

Jul 11, 2006, 6:40 AM

Post #3 of 5 (482 views)
Re: [davorg] Using Perl to interface with web pages [In reply to] Can't Post

Ok I've written the following but I'm getting an error on the form number.


Code
use strict; 
use warnings;
use WWW::Mechanize;

my $accnum="SI000102";

my $mech=WWW::Mechanize->new();
$mech->proxy(['http', 'ftp'] => "http://pac.ncl.ac.uk/default.pac:8081");
$mech->get("http://prodoric.tu-bs.de/ssearch.php");

$mech->form(1);
$mech->field("acc",$accnum);
$mech->click();


The error is:
There is no form numbered 1 at web.pl line 11
Can't call method "value" on an undefined value at C:/Perl/lib/WWW/Mechanize.pm line 1052.

Sorry my inexperience with using this module means I'm not quite sure where the problem is... Any pointers would be appreciated.

Thanks,
Jamie.


davorg
Thaumaturge / Moderator

Jul 11, 2006, 8:19 AM

Post #4 of 5 (479 views)
Re: [jim_lad] Using Perl to interface with web pages [In reply to] Can't Post

I'm not an expert on the module, so all this is from reading the documentation and guessing...

It looks to me as though your code should work. But the docs do say that the "form()" method has been deprecated in favour of "form_name()" and "form_number()". Maybe you could try using one of those instead. The form seems to have the name "site_form".

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


jim_lad
Novice

Jul 12, 2006, 7:45 AM

Post #5 of 5 (474 views)
Re: [davorg] Using Perl to interface with web pages [In reply to] Can't Post

Cheers Dave,

I'm not sure what the problem was but when I ran the code on my home machine rather than at uni it worked fine - maybe a proxy issue, I'm not sure...

Anyways, thanks for your help.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives