download with HTML::FORM login and password on page


W

Winston75

hi,

i don't understand my code is corrupted at form "value" instance??
error prompt : Can't call method "value" on an undefined value at
ligne 27 (here : $form->find_input('txtusername')-
value($user);) ??

any ideas, thanks

#!/usr/bin/perl -w

use strict;
use warnings;
use LWP::UserAgent;
use HTML::Form;

my ($user,$pass ) = qw(username password);
my $base = 'http://www.mysite/login.asp/';

my $ua = LWP::UserAgent->new(agent => 'Microsoft Internet Explorer
6.0' );

my $req = HTTP::Request->new( GET => "${base}" );

my $res = $ua->request($req);
die $res->status_line if not $res->is_success;

my $form = (HTML::Form->parse($res->content, $base))[1];

$form->find_input('txtusername')->value($user);
$form->find_input('txtpassword')->value($pass);

$ua->request($form->click );
 
Ad

Advertisements

P

Peter Makholm

Winston75 said:
i don't understand my code is corrupted at form "value" instance??
error prompt : Can't call method "value" on an undefined value at
ligne 27 (here : $form->find_input('txtusername')-
$form->find_input('txtusername')->value($user);

I assume this is line 27?

What you have is that the find_input method on you HTML::Form object
returns undef. According to the documentation this means that there is
no input in the form matching you criteria.

//Makholm
 
Ad

Advertisements

W

Winston75

I assume this is line 27?

What you have is that the find_input method on you HTML::Form object
returns undef. According to the documentation this means that there is
no input in the form matching you criteria.

//Makholm

thanks for you reponss.
my error was in web adresss:
'http://www.mysite.com/login.asp/';
but
'http://www.mysite.com/login.asp';


OK, next :

#!/usr/bin/perl -w

use strict;
use warnings;
#use diagnostics;

use LWP::UserAgent;
use HTML::Form;
use HTML::SimpleLinkExtor;

my ($user,$pass ) = qw(username password);
my $base = 'http://www.mysite.com/login.asp';
my $ua = LWP::UserAgent->new(agent => 'Microsoft Internet Explorer
6.0' );
my $req = HTTP::Request->new( GET => "${base}" );
my $res = $ua->request($req);
die $res->status_line if not $res->is_success;

my $form = (HTML::Form->parse($res->content, $base))[1];

$form->find_input('txtusername')->value($user);
$form->find_input('txtpassword')->value($pass);

my $base2 ='http://www.mysite.com/database/';
my $ua2 = LWP::UserAgent->new(agent => 'Microsoft Internet Explorer
6.0' );
my $req2 = HTTP::Request->new( GET => "${base2}" );
my $res2 = $ua2->request($req2);
die $res2->status_line if not $res2->is_success;
my $extractor = HTML::SimpleLinkExtor->new($base2);
$extractor->parse($res2->content);
my @allLinks = $extractor->links;


for (@allLinks)
{
if (/DataAge.asp/) {

print $_ . "\n";
}
}


my result & code are correct : print command send me, "www.mysite.com/
DataAge.asp"
however, how to connect on this link, without losing a session with
$user et $pass??
the lib html:linkextractor can extract my link, but not simulate a
CLICK on my new link www.mysite.com/DataAge.asp, for instance.

thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top