how to use Perl to input username and password for website?

P

Paul

hi, greetings,

I am trying to write a script to log on
https://membership.dell.com/DellLogin/GA/login.aspx, so I can track my
order instantly without log on the site each time.
here is the scripts i wrote, but seems it does not work.

can somebody give me some ideas? thanks.

paul

#!/usr/bin/perl


use strict;
use warnings;
use LWP 5.64;

my $browser = LWP::UserAgent->new;
my $sbresponse;

my $sburl = 'https://membership.dell.com/DellLogin/GA/login.aspx';

#############Get the _viewstate##################
$sbresponse = $browser->get($sburl);
print "Error at $sburl\n ", $sbresponse->status_line, "\n Aborting"
unless $sbresponse->is_success;


my $sbident = 'name="__VIEWSTATE" value="';
my $sbpos1 = index($sbresponse->content, $sbident) + length $sbident;
my $sbpos2 = index $sbresponse->content, '"', $sbpos1;
my $sbviewstate=substr($sbresponse->content, $sbpos1,
$sbpos2-$sbpos1);
#############Get _viewstate ends###################


$sbresponse = $browser->post( $sburl,
[ _txtUserName => '(e-mail address removed)',
_txtPassword => 'xxxx',
__EVENTTARGET=>'subBtn',
__EVENTARGUMENT=>'',
__VIEWSTATE=>$sbviewstate,
]
);
print $sbresponse->content;
 
P

Paul Lalli

Paul said:
hi, greetings,

I am trying to write a script to log on
https://membership.dell.com/DellLogin/GA/login.aspx, so I can track my
order instantly without log on the site each time.
here is the scripts i wrote, but seems it does not work.

"Does not work" is the worst possible error description. How does it
not work? What does it do that you didn't expect, or what does it not
do that you did expect? Does it crash? Does it not compile? Did your
computer decide to leap out the window on its own accord? Did it print
"I will not contact this website" fifty times? *What Happened*?
can somebody give me some ideas? thanks.

paul

#!/usr/bin/perl


use strict;
use warnings;
use LWP 5.64;

my $browser = LWP::UserAgent->new;
my $sbresponse;

my $sburl = 'https://membership.dell.com/DellLogin/GA/login.aspx';

#############Get the _viewstate##################
$sbresponse = $browser->get($sburl);
print "Error at $sburl\n ", $sbresponse->status_line, "\n Aborting"
unless $sbresponse->is_success;

So.... if something went wrong, you print an error message and then
continue as though nothing went wrong?
my $sbident = 'name="__VIEWSTATE" value="';
my $sbpos1 = index($sbresponse->content, $sbident) + length $sbident;
my $sbpos2 = index $sbresponse->content, '"', $sbpos1;
my $sbviewstate=substr($sbresponse->content, $sbpos1,
$sbpos2-$sbpos1);
#############Get _viewstate ends###################

Did you try printing any of these variables out to confirm they are
what you think they are? Where is your debugging output? What
attempts have you made to solve this problem on your own?
$sbresponse = $browser->post( $sburl,
[ _txtUserName => '(e-mail address removed)',
_txtPassword => 'xxxx',
__EVENTTARGET=>'subBtn',
__EVENTARGUMENT=>'',
__VIEWSTATE=>$sbviewstate,
]
);
print $sbresponse->content;

You checked the get() above for errors. Why aren't you checking this
post() for errors as well?


Paul Lalli
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top