CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
www::Mechanizee authorization

 



Demerzel
Novice

Aug 15, 2012, 9:25 AM

Post #1 of 2 (5968 views)
www::Mechanizee authorization Can't Post

Using:

Code
my $ua = LWP::UserAgent->new(); 
my $response = $ua->get($lms_url.'/?m=documentview&override=1&original=1&id='.$docid.'&loginform[login]='.$lms_user.'&loginform[pwd]='.$lms_password);

I can print page to file without any problems.
This:

Code
my $ua = WWW::Mechanize->new( autocheck => 1); 
$ua->credentials($lms_user, $lms_password);
$ua->get($lms_url.'/?m=documentview&override=1&original=1&id='.$docid.'&loginform[login]='.$lms_user.'&loginform[pwd]='.$lms_password);
print $ua->content;
$ua->form_name('conform');

is also fine.
But when I click submit in form instead of next page I get page requesting login

Code
my $ua = WWW::Mechanize->new( autocheck => 1); 
$ua->credentials($lms_user, $lms_password);
$ua->get($lms_url.'/?m=documentview&override=1&original=1&id='.$docid.'&loginform[login]='.$lms_user.'&loginform[pwd]='.$lms_password);
print $ua->content;
$ua->form_name('conform');
my $response =$ua->click(); # this throws me out of system

How can I use click and keep logged in? I can start with login form but geting to this page using links at pages will be painful.


wickedxter
User

Sep 4, 2012, 1:47 PM

Post #2 of 2 (4796 views)
Re: [Demerzel] www::Mechanizee authorization [In reply to] Can't Post

This is a small example i made to log u in to the forums here automaticly and will print the main forum page once logged-in. anymore code and URL can u give?

This isn't in answer just an example

Code
use strict; 
use warnings;

use WWW::Mechanize;

my $mech = WWW::Mechanize->new();

#get main site
my $url = 'http://www.perlguru.com';

#username
my $username = '';
#password
my $password = '';


#get main page loaded
$mech->get($url);

#follow link to login screen
$mech->follow_link( n => 2,text_regex => qr/LOG IN|LOGIN|Click here/i );

#get the url we need info from it
my $current_url = $mech->uri();
#get the guest id
$current_url =~ /gforum.cgi\?do=login;guest=(\d+)/;

#Then login
$mech->submit_form(
form_number => 2,
fields => {
login_username => $username,
login_password => $password,
dont_use_cookies => 1,
url => 'http://perlguru.com/gforum.cgi?login_attempt=1',
guest => $1,
}
);

if($mech->success()){
print $mech->content;
}else {
print "Opps some error happend";
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives