Login using perl LWP module


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Login using perl LWP module
# 1  
Old 11-25-2010
Login using perl LWP module

Hi,

Could some one tell me how to login to any web site and get that page using perl LWP. I heard that we can login to the site using LWP.

I dont want to use WWW:Mechanize as I dont have that module installed on the server.

Appreciate your early response.

Thanks...
# 2  
Old 11-25-2010
Depends on the web site. What is it?

Some accept simple http://user:pass@hostname/ logins and those are all done the same way. But these days, this is rare.

Others require you to post user and password data into a form, then pass on the resulting cookie to future web requests, which is really annoying to have to do automatically.
# 3  
Old 11-25-2010
Code:
#!usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use HTTP::Cookies;
 
$user = xxxx;
$pass = xxxx;
 
my $ua = LWP::UserAgent->new;
 $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt",autosave => 1));
 my $req = HTTP::Request->new(GET => 'http://www.drivehq.com/Secure/LogonOption.aspx?gotoURL=');
 
 $req->authorization_basic($user, $pass);
 
 my $content = $ua->request($req)->as_string;
print "$content\n";

Above is the code I am using. I am trying to access "http://drivehq.com"

Last edited by Anjan1; 11-25-2010 at 05:10 PM.. Reason: given wrong data
# 4  
Old 11-25-2010
Obviously I can't test it given I don't have the username and pw but that site is definitely not using basic authentication. They've got a login form on their mainpage like so:

Code:
<form name="aspnetForm" method="post" action="index.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODk3NjczNDQzZBgKBRdjdGwwMCRtdHZNYWluVGFiU..." />
</div>

...

      <div class="logonCont">      
      
                
                <i>Username:</i><input name="ctl00$ContentPlaceHolder1$LogonUserNameTextBox" type="text" maxlength="50" id="ctl00_ContentPlaceHolder1_LogonUserNameTextBox" class="unnamed1" />
...
                <i>Password:</i><input name="ctl00$ContentPlaceHolder1$LogonPasswordTextBox" type="password" maxlength="20" id="ctl00_ContentPlaceHolder1_LogonPasswordTextBox" class="unnamed1" />
...
                <input type="image" name="ctl00$ContentPlaceHolder1$LogonButtons" id="ctl00_ContentPlaceHolder1_LogonButtons" class="BtnLogon" 
...
</form>

I adore the glorious futility of putting hidden elements inside their own <div> Smilie But anyway. You'll need to POST some data like
Code:
ctl00$ContentPlaceHolder1$LogonUserNameTextBox=xxxx&ctl00$ContentPlaceHolder1$LogonPasswordTextBox=xxxx

to http://drivehq.com/index.aspx, and you might need to throw all those hidden variables in along with it. See what I mean by annoying?

Last edited by Corona688; 11-25-2010 at 06:59 PM..
# 5  
Old 11-25-2010
Thanks for your reply...

Actaully I have to login to this site "http://zip-codes.com" using LWP and after log into the site, need to go to "Database Downloads" link.

Username: Matt123
Password: usermatt

Can you pls paste the code and if possible explanation...

Thanks.....

Last edited by Anjan1; 11-25-2010 at 07:33 PM.. Reason: modification
# 6  
Old 11-25-2010
Is this real username and password? If so, please dont post them
# 7  
Old 11-26-2010
If you want us to write and test every last scrap of code for you this is the wrong place to look. Services like vworker are plentiful.

As already said: It's a pain. You have to emulate every last scrap of whatever convoluted login system they're using, which may involve hacks like javascript redirects.

This is what I tried and it just doesn't work and only zip-code.com can tell you why.

Code:
TMP=`mktemp`
wget --save-cookies "$TMP" --keep-session-cookies -U netscape --referer=http://zip-codes.com/ "http://zip-codes.com/account_login.asp" --post-data="loginUsername=xxxx&loginPassword=xxxx&redir=account_home.asp&Action=Login&Submit=Login"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing a webpage - perl lwp

I am requesting for the text parsing section below. Any helps are highly appreciated. <tr valign="top"><td nowrap>Source name</td> <td style="text-align: justify">Sample Name<br></td> I want Sample Name from above. In the same file, I have to search for another pattern like this <td><a... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

2. Shell Programming and Scripting

Perl SSH without a perl module

I'm trying to create a perl script that will do 1 SSH session, but be able to write multiple commands to the session and receive multiple outputs. I know there are modules out there like Net:SSH::Perl, but I'm not allowed to use it. I was thinking of doing something like an open3 on an ssh... (4 Replies)
Discussion started by: mrwatkin
4 Replies

3. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

4. Shell Programming and Scripting

Perl LWP user authentication

Hello all.. i am new to perl scripting.. i wanted to parse a text file, encode the parsed text and attach in url.. please point me to right resources if you know any..This is my major problem. Now i try to get a url running and save it in a text file using LWP module in perl, I used following... (0 Replies)
Discussion started by: empyrean
0 Replies

5. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

6. Shell Programming and Scripting

How to call a shell script from a perl module which uses Filehandle to login

Hi Guru's, Pardon me for the breach of rules..... I have very little knowledge about Shell Programming and Scripting hope you guys help me out of this troble I have very little time hence could not find the right way to direct my queries. coming to the problem I need to call a... (2 Replies)
Discussion started by: saikrishna_tung
2 Replies

7. Shell Programming and Scripting

Help with Perl Module

I dont know if this is a dumb question, but I am unable to move ahead and need help - There is a perl module called Header.pm which was written by someone else. I am trying to write a simple perl script which uses a function provided by the module. The function has been exported by the module... (9 Replies)
Discussion started by: NewDeb
9 Replies

8. Shell Programming and Scripting

Help needed in Perl LWP module

Hi, I've a issue in writing a perl script that will automatically monitor the site availability. There are two different cookies are set in two consecutive flows to a URL and this second cookie has to be passed to the third step which actually gives permission to access based upon the cookie. ... (1 Reply)
Discussion started by: dayanandra
1 Replies

9. Shell Programming and Scripting

Replace Perl Module name in all Perl scripts

I want to replace a Perl module name in all my Perl Scripts in the cgi-bin directory. How is it possible? I have the following statement in my scripts use myUtil; I want to change it to use myUtil777; Regards, Rahul (2 Replies)
Discussion started by: rahulrathod
2 Replies

10. UNIX for Dummies Questions & Answers

LWP module ?

my host run on a Free bsd server and i have a cgi script that requires LWP module, but i my host say that that module is installed, so i would like to know if the is a command because i have telnet access to know if the module or which modules are installed on my account (itīs that the script donīt... (4 Replies)
Discussion started by: Beto
4 Replies
Login or Register to Ask a Question