Automating a web page login and clicking a link.

I'm very new to perl+lwp so please excuse mis-statements.

I'm trying to automate a web task. Here's the steps I do by hand:

Load a main web page
fill in a form with username/pass
submit
click a link on the resulting page
grab some data off the next page

The last page reloads every 30 secons through what appears to be some
php scripting and I need to keep grabbing data off it to dump in a
text file. I started with WWW::Mechanize which seems to work nicely
but when I submit the form I get an error from the server telling me I
need to enable cookies. Here's the start of the sample code
(login/pass) have been munged. Once I get this working I need to
backport it to a more complicated page for school which does the same
thing though.

------------------------------------------------------------ -------

#!/usr/bin/perl -w
$|++;

my ($TopURL)=3D"http://www.site.com/index.php";

use strict;
use diagnostics;
use WWW::Mechanize;
my $mech =3D WWW::Mechanize->new( autocheck=3D>1, cookie_jar=3D>{ file =3D>
"$ENV{HOME}/.cookies.txt"} );
$mech->agent_alias( 'Windows IE 6' );
$mech->get( $TopURL ) || die "Can't Connect to $TopURL : $!";


#
my ($UserName)=3D"Foo";
my ($Passwd)=3D"Bar";

my ($tmp, $loop, [at] foo, $Content, $PHPSessID);

# Log in.
$mech->submit_form(
form_number =3D> 1,
fields =3D> { 'username' =3D> '$UserName', 'password' =3D> '$Passwd'
}
);
print $mech->content();




--

:wq!
------------------------------------------------------------ ---------------
Robert L. Harris

DISCLAIMER:
These are MY OPINIONS With Dreams To Be A King,
ALONE. I speak for First One Should Be A Man
no-one else. - Manowar


--

:wq!
------------------------------------------------------------ ---------------
Robert L. Harris

DISCLAIMER:
These are MY OPINIONS With Dreams To Be A King,
ALONE. I speak for First One Should Be A Man
no-one else. - Manowar
Robert.L.Harris [ Mo, 13 Juni 2005 21:01 ] [ ID #835763 ]
Perl » perl.libwww » Automating a web page login and clicking a link.

Vorheriges Thema: Cookie problem ?
Nächstes Thema: Waiting for resultpage...