Curl technology is to imitate the browser's actions to achieve page crawl or form submission, through this technology can achieve a lot of functions to go.
Copy CodeThe code is as follows:
error_reporting (0);
Mailbox user name (without @163.com suffix)
$user = ' papatata_test ';
Email password
$pass = ' 000000 ';
Target Mailbox
$mail _addr = Uenucom@163.com ';
Landing
$url = ' Http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2? Lightweight%3d1%26verifycookie%3d1%26language%3d-1%26style%3d-1 ';
$ch = Curl_init ($url);
Create a temporary file for storing cookie information
$cookie = Tempnam ('. ', ' ~ ');
$referer _login = ' http://mail.163.com ';
The returned result is stored in a variable instead of the default direct output
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_connecttimeout, 120);
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_referer, $referer _login);
$fields _post = Array (
' Username ' = $user,
' Password ' = $pass,
' Verifycookie ' =>1,
' Style ' =>-1,
' Product ' = ' mail163 ',
' SelType ' =>-1,
' Secure ' = ' on '
);
$headers _login = Array (
' User-agent ' = ' mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9) gecko/2008052906 firefox/3.0 ',
' Referer ' = ' http://www.163.com '
);
$fields _string = ";
foreach ($fields _post as $key = $value)
{
$fields _string. = $key. '=' . $value. ' & ';
}
$fields _string = RTrim ($fields _string, ' & ');
curl_setopt ($ch, curlopt_cookiesession, true);
When the connection is closed, the cookie returned by the server is saved in the following file
curl_setopt ($ch, Curlopt_cookiejar, $cookie);
curl_setopt ($ch, Curlopt_httpheader, $headers _login);
curl_setopt ($ch, Curlopt_post, Count ($fields));
curl_setopt ($ch, Curlopt_postfields, $fields _string);
$result = curl_exec ($ch);
Curl_close ($ch);
Jump
$url = ' http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1& Style=-1&username=loki_wuxi ';
$ch = Curl_init ($url);
$headers = Array (
' User-agent ' = ' mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9) gecko/2008052906 firefox/3.0 '
);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_connecttimeout, 120);
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_httpheader, $headers);
Send the previously saved cookie information to the server side
curl_setopt ($ch, Curlopt_cookiefile, $cookie);
curl_setopt ($ch, Curlopt_cookiejar, $cookie);
$result = curl_exec ($ch);
Curl_close ($ch);
Get SID
Preg_match ('/sid=[^\ '].*/', $result, $location);
$sid = substr ($location [0], 4,-1);
File_put_contents ('./result.txt ', $sid);
Address Book
$url = ' http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid= '. $sid. ' &gid=all ';
$ch = Curl_init ($url);
$headers = Array (
' User-agent ' = ' mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9) gecko/2008052906 firefox/3.0 '
);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_connecttimeout, 120);
curl_setopt ($ch, Curlopt_post, true);
curl_setopt ($ch, Curlopt_httpheader, $headers);
curl_setopt ($ch, Curlopt_cookiefile, $cookie);
curl_setopt ($ch, Curlopt_cookiejar, $cookie);
$result = curl_exec ($ch);
Curl_close ($ch);
File_put_contents ('./result.txt ', $result);
Unlink ($cookie);
Start crawling content
Preg_match_all ('/]*> (. *?) <\/a><\/td>]*> (. *?) <\/a><\/td>/i ', $result, $infos, Preg_set_order);
1: Name 2: Email
Print_r ($infos);
?>
http://www.bkjia.com/PHPjc/323203.html www.bkjia.com true http://www.bkjia.com/PHPjc/323203.html techarticle Curl Technology is to imitate the browser's actions to achieve page crawl or form submission, through this technology can achieve a lot of functions to go. Copy the code code as follows: PHP error_report ...