Perl_Love has asked for the wisdom of the Perl Monks concerning the following question:

Hello, everyone, I have a simulation of the site of the problem please master pointing!

A lot of Web site simulation login I can use Perl to achieve, but encountered a website more special, it should be more difficult to get.

Login interface is as follow:

https://passport.ganji.com/login.php?next=/

I wrote the code is as follows, the user name password is specially registered for testing, to facilitate everyone to test.

username:Perl_Login_Test password:Km97Jc8YA0hBtDWa username:Perl_Login_Test2 password:Km97Jc8YA0hBtDWb username:Perl_Login_Test3 password:Km97Jc8YA0hBtDWc username:Perl_Login_Test4 password:Km97Jc8YA0hBtDWd username:Perl_Login_Test5 password:Km97Jc8YA0hBtDWe username:Perl_Login_Test6 password:Km97Jc8YA0hBtDWf
I use HttpFox to capture the information is logged in will GET this URL.
https://passport.ganji.com/login.php?callback=jQuery182024004868176778 +26_1465784917412&username=Perl_Login_Test&password=Km9%24Jc8%23A0hb&c +heckCode=&setcookie=0&second=&parentfunc=&redirect_in_iframe=&next=%2 +F&__hash__=g9HXulwHOtjjvcVkbJJ3xO2sNdOiS%2F2orrB9fkSBiYSeqFdzpasFkX%2 +F7R2terabF&_=1465784941421
My own analysis is as follows, may not be correct, please correct me, thank you!

__hash__=This parameter should be got from Https://passport.ganji.com/login.php? Next=/?

&_=This maybe means the current time seconds, 13 digit

&checkCode=This is means picture verification code, if needed.

These numbers1820xxxx may be a random number, I do not know how to get this random number, so I used a fixed number, followed by the 13 digit number should be the time, may be from obtain from Https://passport.ganji.com/login.php? Next=/?

In addition, Headers information I also use HttpFox analysis, only one cookie I did not add parameters, because the cookie can not read, can only be passed by Mojo:: UserAgent.

The most difficult,more than a few images appear after the image verification code, how can get the picture verification code?I then manually view the image verification code, the program waiting for manual input automatically log on? How to solove this problem? thanks a lot !

#!/usr/bin/perl $|=1; use Time::HiRes qw/time/; use Data::Dumper; use Mojo::UserAgent; use Mojo::UserAgent::CookieJar; my $ua=Mojo::UserAgent->new; $ua=$ua->inactivity_timeout(10); $ua = $ua->max_redirects(10); my $jar=Mojo::UserAgent::CookieJar->new; $ua = $ua->cookie_jar($jar); my $time1; my $hash; my $login=$ua->get('https://passport.ganji.com/login.php?next=/'=>{ 'Host'=>'passport.ganji.com', 'User-Agent'=>'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/2010 +0101 Firefox/45.0', 'Accept'=>'text/html,application/xhtml+xml,application/xml;q=0.9,* +/*;q=0.8', 'Accept-Language'=>'en-US,en;q=0.5', 'Accept-Encoding'=>'gzip, deflate;', 'Connection'=>'keep-alive', }); if(my $res0=$login->success){ my $body0=$res0->body; if($body0=~m/"display: none">(\d{13})\<\/div\>/){ $time1=$1; } if($body0=~m/\_\_hash\_\_ \= '(.*?)\'\;/){ $hash=$1; } } my $time2=time; $time2=~s/\.//; $time2=~m/^(\d{13})/; $time2=$1; my $url='https://passport.ganji.com/login.php?callback=jQuery182078315 +63733301097_'.$time1.'&username=Perl_Login_Test&password=Km97Jc8YA0hB +tDWa&checkCode=&setcookie=0&second=&parentfunc=&redirect_in_iframe=&n +ext=%2F&__hash__='.$hash.'&_='.$time2; my $tx=$ua->post($url=>{ 'Host'=>'passport.ganji.com', 'User-Agent'=>'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/2010 +0101 Firefox/45.0', 'Accept'=>'text/javascript, application/javascript, application/ec +mascript, application/x-ecmascript, */*; q=0.01', 'Accept-Language'=>'en-US,en;q=0.5', 'Accept-Encoding'=>'gzip, deflate;', 'X-Requested-With'=>'XMLHttpRequest', 'Referer'=>'https://passport.ganji.com/login.php?next=/', 'Connection'=>'keep-alive', }); if(my $res=$tx->success){ print Dumper ($res); my $gh=$ua->get('http://www.ganji.com/user/login_success.php?usern +ame=Perl_Login_Test&next=%2F&second='); if(my $res2=$gh->success){ my $body2=$res2->body; print "$body2\n"; } } else{ print "ERROR!!!\n"; }

Replies are listed 'Best First'.
Re: Consult a difficulty of the analog login site.
by marto (Cardinal) on Jun 14, 2016 at 12:38 UTC

    From your description the owners of the site don't want people to automate logins to this web interface, hence the picture verification and so on. If you have legitimate reasons to access this system I'm sure the owners will provide you with an API to do so.

    Update: slight rewording for clarity.

      Hi Marto, thank you for your reply! I am an ordinary Perl fan, there is no way to make web API interface , but I want to log on to the website and make some operations to more automated . So I need to use Perl. The authentication code is a site set of barriers, but I do not need to break through this obstacle. I just need to download the picture verification code. And then manual input automatically log in. Thank you again!
        ok, I do it, yeah~~