色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php curl 登錄163郵箱并抓取郵箱好友列表的代碼(經測試)

CURL技術說白了就是模擬瀏覽器的動作實現頁面抓取或表單提交,通過此技術可以實現許多有去的功能。
復制代碼 代碼如下:
<?php
error_reporting(0);
//郵箱用戶名(不帶@163.com后綴的)
$user = 'papatata_test';
//郵箱密碼
$pass = '000000';
//目標郵箱
//$mail_addr = uenucom@163.com';
//登陸
$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);
//創建一個用于存放cookie信息的臨時文件
$cookie = tempnam('.','~');
$referer_login = 'http://mail.163.com';
//返回結果存放在變量中,而不是默認的直接輸出
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);
//關閉連接時,將服務器端返回的cookie保存在以下文件中
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);
//跳轉
$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);
//將之前保存的cookie信息,一起發送到服務器
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//取得sid
preg_match('/sid=[^/"].*/', $result, $location);
$sid = substr($location[0], 4, -1);
//file_put_contents('./result.txt', $sid);
//通訊錄地址
$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);
//開始抓取內容
preg_match_all('/<td class="Ibx_Td_addrName"><a[^>]*>(.*?)<//a><//td><td class="Ibx_Td_addrEmail"><a[^>]*>(.*?)<//a><//td>/i', $result,$infos,PREG_SET_ORDER);
//1:姓名2:郵箱
print_r($infos);
?>

php技術php curl 登錄163郵箱并抓取郵箱好友列表的代碼(經測試),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 彰化县| 临清市| 阳曲县| 霍城县| 屏边| 沙雅县| 宜宾县| 奉节县| 梧州市| 增城市| 郎溪县| 靖边县| 侯马市| 田阳县| 玛曲县| 琼中| 布拖县| 西盟| 博乐市| 河北省| 双辽市| 奉贤区| 天峨县| 开江县| 建瓯市| 北票市| 根河市| 罗田县| 通山县| 青河县| 华坪县| 遂昌县| 兰州市| 东乡县| 安泽县| 清水河县| 大渡口区| 阿拉善盟| 崇义县| 讷河市| 淮安市|