Find some on the internet, most of them have been invalidated, for this I have to rearrange a bit; special release of 126 of the code, 163 is easier to crawl; 126 a little sick more than a jump, more trouble
Copy Code code as follows:
<?php
/**
* @file class.126http.php
* Get 126 Email address List
* @author jvones<jvones@gmail.com> Http://www.jvones.com/blog
* @date 2009-09-26
**/
Class http126
{
Private Function Login ($username, $password)
{
First step: initial landing
$cookies = Array ();
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_url, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http:// Entry.mail.126.com/cgi/ntesdoor?hid%3d10010102%26lightweight%3d1%26verifycookie%3d1%26language%3d0%26style% 3d-1 ");
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, "username=". $username. " @126.com&password= ". $password);
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
curl_setopt ($ch, curlopt_header,1);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
curl_setopt ($ch, Curlopt_returntransfer, true);
$str = curl_exec ($ch);
File_put_contents ('./126result.txt ', $str);
Curl_close ($ch);
Gets the Redirect_url jump address, which can be viewed from the 126result.txt, matching the address in the $str return stream by a regular
Preg_match ("/replace\" (. *?) \ "\) \;/", $str, $mtitle);
$_URL1 = $mtitle [1];
File_put_contents ('./126resulturl.txt ', $redirect _url);
Step two: Jump again to the top $_URL1
$ch = Curl_init ($_URL1);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_cookiefile,cookiejar);
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
curl_setopt ($ch, curlopt_header,1);
$str 2 = curl_exec ($ch);
Curl_close ($ch);
if (Strpos ($contents, "safe exit")!== false)
{
return 0;
}
return 1;
}
/**
* Get mail Address Book-Addresses
* @param $user
* @param $password
* @param $result
* @return Array
*/
Public Function Getaddresslist ($username, $password)
{
if (! $this->login ($username, $password))
{
return 0;
}
$header = $this->_getheader ($username);
if (! $header [' Sid '])
{
return 0;
}
Test to find SID (very important) and host
File_put_contents ('./host.txt ', $header [' Host ']);
File_put_contents ('./sid.txt ', $header [' Sid ']);
Start into the simulation crawl
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://". $header [' Host ']. " /a/s?sid= ". $header [' Sid ']." &func=global:sequential ");
curl_setopt ($ch, Curlopt_cookiefile, Cookiejar);
curl_setopt ($ch, Curlopt_httpheader, Array ("Content-type:application/xml"));
$str = "<?xml version=\" 1.0\ "><object><array name=\" items\ "><object><string name=\" func \ ">pab:searchcontacts</string><object name=\" var\ "><array name=\" Order\ "><object>< String name=\ "field\" >fn</string><boolean name=\ "ignorecase\" >true</boolean></object> </array></object></object><object><string name=\ "Func\" >user:getSignatures</ String></object><object><string name=\ "Func\" >pab:getallgroups</string></object ></array></object> ";
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, $STR);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
Ob_start ();
Curl_exec ($ch);
$contents = Ob_get_contents ();
Ob_end_clean ();
Curl_close ($ch);
Get mail list from the page information username && emailaddress
Preg_match_all ("/<string\s*name=\" EMAIL; Pref\ "> (. *) <\/string>/umsi", $contents, $mails);
Preg_match_all ("/<string\s*name=\" fn\ "> (. *) <\/string>/umsi", $contents, $names);
$users = Array ();
foreach ($names [1] as $k => $user)
{
$user = Iconv ($user, ' utf-8 ', ' gb2312 ');
$users [$mails [1][$k]] = $user;
}
if (! $users)
{
Return ' no contact in your mailbox ';
}
return $users;
}
/**
* Get Header Info
*/
Private Function _getheader ($username)
{
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1& Verifycookie=1&language=0&style=-1&username= ". $username." @126.com ");
curl_setopt ($ch, Curlopt_cookiefile, Cookiejar); Cookies currently in use
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar); New cookies returned by the server
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_nobody, true);
$content =curl_exec ($ch);
Preg_match_all ('/location:\s* (. *?) \r\n/i ', $content, $regs);
$refer = $regs [1][0];
Preg_match_all ('/http\:\/\/(. *?) \//i ', $refer, $regs);
$host = $regs [1][0];
Preg_match_all ("/sid= (. *)/I", $refer, $regs);
$sid = $regs [1][0];
Curl_close ($ch);
Return Array (' SID ' => $sid, ' refer ' => $refer, ' host ' => $host);
}
}
?>