Finally
Succeeded in making the Perl Script that logs you into Orkut! Signing into Orkut is much more than a simple POST, Google is always clever so that they make things complex for automating the login process. Anyway here is the complex script, ..
Algorithm
- Goto www.orkut.com
- Check whether the title is Home.
- If not find the source of login page IFRAME
- Fill the username and password and submit the FORM.
- Find the follow link from the next page.
- Goto the followlink and GET the redirect page URL
- Goto the redirect page
- Goto Orkut.com/home.aspx
- Your done.
Note:Tested on Linux (FC6, Perl 5.8.8)
The following script is for linux, Will run on
Windows too but the ANSI coloring may not work...
Windows Program is given below the program for Linux (without ANSI coloring).
For Linux (with ANSI coloring)
use WWW::Mechanize;
use HTTP::Cookies;
use HTTP::Request::Common;
$cj=HTTP::Cookies->new(file => "cookie.jar",autosave=>1,ignore_discard=>1);
$mech = WWW::Mechanize->new(cookie_jar => $cj);
@prc = ("\e[0m\n","[\e[1;31mFAILED\e[0m]","[\e[2;32m OK \e[0m]\n");
print "\n\e[31;1mG\e[0mmail iD : ";
$email = ;
print "\e[31;1mP\e[0massword : \e[97m";
$pass = ;
print $prc[0];
chomp $email;chomp $pass;
RELOGIN:
for($i=3; $i>=0;$i--)
{
printf("\e[2m%-60s","GET /Home.aspx");
$mech->get("http://www.orkut.com/Home.aspx");
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if($mech->title =~ m/orkut.*home/i)
{
print "\n\e[34mAlready Logged In",$prc[0];
$cnt =~ m/<b>(.*)\@gmail.com<\/b>/;
print "\nLogout $1?[n] : ";
$com=;chomp $com;
if($com eq "y")
{
logout;
goto RELOGIN;
}
else
{
return;
}
}
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
printf("\e[2m%-60.59s","Parsing for Login Page ");
#print $cnts;
if($cnt !~ m/id='liframe'.*?src='(.*)'/)
{
printf("%10s",$prc[1]);
print "\e[2;37m Login page URL Not Found!\nTry Again OR Update the script! ".$prc[0];
return;
}
print $prc[2];
$url = $1;
$j=3;
REDO:
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
$mech->form_number(1);
$mech->field("Email",$email."\@gmail.com");
$mech->field("Passwd",$pass);
printf("\e[2m%-60.59s","Logging In ... ");
$mech->click("null");
$j--;
if($j && !$mech->success())
{
printf("%10s\n",$prc[1]);
goto REDO;
}
return unless($j);
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if(!$mech->find_link(text => "click here to continue"))
{
printf("%10s",$prc[1]);
print "\n\e[31;1mWrong Usename or Password!",$prc[0];
return;
}
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","Continuing ...");
$mech->follow_link(text => "click here to continue");
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
printf("\e[2m%-60s","Parsing REDIRECT URL");
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if($cnt !~ m/location.replace\("(.*)"\)/)
{
printf("%10s",$prc[1]);
print "\n\e[31;1mRedirect script missing!",$prc[0];
return;
}
$url = $1;
$url =~ s/\\u003d/=/g;
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
print "\e[34mLogged In!\e[0m";
exit 0;
sub logout
{
printf("\e[0;2m%-60s","Parsing Logout");
if(!$mech->find_link(text => "Logout"))
{
printf("%10s",$prc[1]);
print "\n\e[31;1mNot Logged In?",$prc[0];
return;
}
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("\e[2m%-60.59s","Logging Out ...");
$mech->follow_link(text => "Logout");
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
}
For windows:
use WWW::Mechanize;
use HTTP::Cookies;
use HTTP::Request::Common;
$cj=HTTP::Cookies->new(file => "cookie.jar",autosave=>1,ignore_discard=>1);
$mech = WWW::Mechanize->new(cookie_jar => $cj);
@prc = ("\n","[FAILED]","[ OK ]\n");
print "\nEmail iD : ";
$email = ;
print "Password : \e[97m";
$pass = ;
print $prc[0];
chomp $email;chomp $pass;
RELOGIN:
for($i=3; $i>=0;$i--)
{
printf("%-60s","GET /Home.aspx");
$mech->get("http://www.orkut.com/Home.aspx");
last if($mech->success());
printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if($mech->title =~ m/orkut.*home/i)
{
print "\nAlready Logged In",$prc[0];
$cnt =~ m/<b>(.*)\@gmail.com<\/b>/;
print "\nLogout $1?[n] : ";
$com=;chomp $com;
if($com eq "y")
{
logout;
goto RELOGIN;
}
else
{
return;
}
}
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
printf("%-60.59s","Parsing for Login Page ");
#print $cnts;
if($cnt !~ m/id='liframe'.*?src='(.*)'/)
{
printf("%10s",$prc[1]);
print "Login page URL Not Found!\nTry Again OR Update the script! ".$prc[0];
return;
}
print $prc[2];
$url = $1;
$j=3;
REDO:
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());
printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
$mech->form_number(1);
$mech->field("Email",$email."\@gmail.com");
$mech->field("Passwd",$pass);
printf("%-60.59s","Logging In ... ");
$mech->click("null");
$j--;
if($j && !$mech->success())
{
printf("%10s\n",$prc[1]);
goto REDO;
}
return unless($j);
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if(!$mech->find_link(text => "click here to continue"))
{
printf("%10s",$prc[1]);
print "\nWrong Usename or Password!",$prc[0];
return;
}
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","Continuing ...");
$mech->follow_link(text => "click here to continue");
last if($mech->success());
printf("%10s",$prc[1]);
print "Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
printf("%-60s","Parsing REDIRECT URL");
$cnt = $mech->response->as_string;
$cnt =~ s/\n|\s+/ /g;
if($cnt !~ m/location.replace\("(.*)"\)/)
{
printf("%10s",$prc[1]);
print "\nRedirect script missing!",$prc[0];
return;
}
$url = $1;
$url =~ s/\\u003d/=/g;
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","GET $url");
$mech->get($url);
last if($mech->success());
printf("%10s",$prc[1]);
print " Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
print "Logged In!";
exit 0;
sub logout
{
printf("%-60s","Parsing Logout");
if(!$mech->find_link(text => "Logout"))
{
printf("%10s",$prc[1]);
print "\nNot Logged In?",$prc[0];
return;
}
print $prc[2];
for($i=3;$i>=0;$i--)
{
printf("%-60.59s","Logging Out ...");
$mech->follow_link(text => "Logout");
last if($mech->success());
printf("%10s",$prc[1]);
print "\e[2;37m Retry (",$i,")".$prc[0] if($i);
}
return if($i<=0);
print $prc[2];
}
Libs neededLWP;
WWW::Mechanize;
DescriptionScript that logs you into orkut, It has its own Fail-retry methods and all the action is presented neatly in the terminal, using color codes (
ANSI Escape sequences for LINUX)
There is more of this script currently in the beta version, for mass scrapping etc. For more information about the beta codes, leave your email as a comment.
Bugs ?Please do let me know the bugs , so that i can update the script here...
It works for me... Did it work for you? Let me know... (else I may think this is all crap!)
Happy Automating,.. :)