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";
}