Ron:

You code worked well.  I just have one question...how do I get the final
page that I was supposed to be redirected to once I logged in.  Below is the
code I tried with the goal of having the final web page text in the temp
HTML file; what I get now seems to be the cookie data.  I tried
"$response->content" also but it was empty.

use strict;
use HTTP::Request::Common;
use HTML::Form;
use LWP::UserAgent;
#use LWP::Debug qw(+);
use HTTP::Cookies;
use FileHandle;

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

$ua->agent("Automation/0.1");
$ua->cookie_jar(
  HTTP::Cookies->new( autosave => 1 ));

my $request = $ua->request( POST
'http://online.wsj.com/login?URI=%2Fdocuments%2Fdatabank.htm');

my $form = HTML::Form->parse( $request->content, $request->base());
#print $form->dump;
$form->value( 'Login',   "kcmria" );
$form->value( 'Password', "money" );

my $response = $ua->request( $form->click() );

my @outputLines = split(/\n/, $response->as_string);

my $outputFileHandle = new FileHandle;
$outputFileHandle->open(">d:\\etl\\temp\\temp.html");

foreach my $line (@outputLines)
{
   print $outputFileHandle $line;
}
$outputFileHandle->close;

#print $response ->as_string;

Thanks,
Kenny

----- Original Message -----
From: "Hill, Ronald" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 09, 2002 11:13 AM
Subject: RE: Logging in to form based log in page


>
>
> > -----Original Message-----
> > From: Kenny G. Dubuisson, Jr. [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, July 09, 2002 7:59 AM
> > To: [EMAIL PROTECTED]
> > Subject: Logging in to form based log in page
> >
> >
> > Hello all.  I'm trying to write a script that logs in to a
> > web page that has the user name and password input boxes as
> > part of the initial web page.  I've tried doing a "POST" with
> > the user name and password declarations and values in the
> > request to no avail.  Here is my code:
>
> [snipped]
>
> Hi Kenny;
>
> Try something like this.This should get you started.
> hope this helps :-)
>
> Ron Hill
>
> use strict;
> use HTTP::Request::Common;
> use HTML::Form;
> use LWP::UserAgent;
> use LWP::Debug qw(+);
> use HTTP::Cookies;
>
> my $ua = LWP::UserAgent->new();
>
> $ua->agent("Automation/0.1");
> $ua->cookie_jar(
>   HTTP::Cookies->new( autosave => 1 ));
>
> my $request = $ua->request( POST
> 'http://online.wsj.com/login?URI=%2Fdocuments%2Fdatabank.htm');
>
> my $form = HTML::Form->parse( $request->content, $request->base());
> print $form->dump;
> $form->value( 'Login',   "xyz" );
> $form->value( 'Password', "123" );
>
> my $response = $ua->request( $form->click() );
>
> print $response ->as_string;

Reply via email to