php curl 登錄163郵箱并抓取郵箱好友列表的代碼(經(jīng)測(cè)試)
更新時(shí)間:2011年04月07日 18:17:39 作者:
PHP模擬登陸獲取163郵箱聯(lián)系人的實(shí)現(xiàn)代碼,需要的朋友可以參考下。
CURL技術(shù)說白了就是模擬瀏覽器的動(dòng)作實(shí)現(xiàn)頁(yè)面抓取或表單提交,通過此技術(shù)可以實(shí)現(xiàn)許多有去的功能。
<?php
error_reporting(0);
//郵箱用戶名(不帶@163.com后綴的)
$user = 'papatata_test';
//郵箱密碼
$pass = '000000';
//目標(biāo)郵箱
//$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);
//創(chuàng)建一個(gè)用于存放cookie信息的臨時(shí)文件
$cookie = tempnam('.','~');
$referer_login = 'http://mail.163.com';
//返回結(jié)果存放在變量中,而不是默認(rèn)的直接輸出
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);
//關(guān)閉連接時(shí),將服務(wù)器端返回的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);
//跳轉(zhuǎn)
$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信息,一起發(fā)送到服務(wù)器端
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);
//開始抓取內(nèi)容
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);
?>
復(fù)制代碼 代碼如下:
<?php
error_reporting(0);
//郵箱用戶名(不帶@163.com后綴的)
$user = 'papatata_test';
//郵箱密碼
$pass = '000000';
//目標(biāo)郵箱
//$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);
//創(chuàng)建一個(gè)用于存放cookie信息的臨時(shí)文件
$cookie = tempnam('.','~');
$referer_login = 'http://mail.163.com';
//返回結(jié)果存放在變量中,而不是默認(rèn)的直接輸出
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);
//關(guān)閉連接時(shí),將服務(wù)器端返回的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);
//跳轉(zhuǎn)
$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信息,一起發(fā)送到服務(wù)器端
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);
//開始抓取內(nèi)容
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);
?>
您可能感興趣的文章:
- PHPMailer使用教程(PHPMailer發(fā)送郵件實(shí)例分析)
- 有關(guān)phpmailer的詳細(xì)介紹及使用方法
- PHPMailer郵件類利用smtp.163.com發(fā)送郵件方法
- PHPMailer安裝方法及簡(jiǎn)單實(shí)例
- PHPMailer郵件發(fā)送的實(shí)現(xiàn)代碼
- 163的郵件用phpmailer發(fā)送(實(shí)例詳解)
- ThinkPHP利用PHPMailer實(shí)現(xiàn)郵件發(fā)送實(shí)現(xiàn)代碼
- PHP使用PHPMailer發(fā)送郵件的簡(jiǎn)單使用方法
- PHP郵件發(fā)送類PHPMailer用法實(shí)例詳解
- PHP+Ajax異步通訊實(shí)現(xiàn)用戶名郵箱驗(yàn)證是否已注冊(cè)( 2種方法實(shí)現(xiàn))
- phpmailer綁定郵箱的實(shí)現(xiàn)方法
相關(guān)文章
PHP+mysql實(shí)現(xiàn)的三級(jí)聯(lián)動(dòng)菜單功能示例
這篇文章主要介紹了PHP+mysql實(shí)現(xiàn)的三級(jí)聯(lián)動(dòng)菜單功能,涉及mysql數(shù)據(jù)庫(kù)創(chuàng)建、數(shù)據(jù)添加及php讀取mysql、創(chuàng)建聯(lián)動(dòng)菜單相關(guān)操作技巧,需要的朋友可以參考下2019-02-02php+AJAX傳送中文會(huì)導(dǎo)致亂碼的問題的解決方法
關(guān)于在AJAX中GET回的ResponseText中文亂碼的最簡(jiǎn)解決辦法2008-09-09PHP實(shí)現(xiàn)獲取毫秒時(shí)間戳的方法【使用microtime()函數(shù)】
這篇文章主要介紹了PHP實(shí)現(xiàn)獲取毫秒時(shí)間戳的方法,結(jié)合實(shí)例形式分析了php使用microtime()函數(shù)獲取、轉(zhuǎn)換毫秒級(jí)時(shí)間戳的相關(guān)操作技巧,需要的朋友可以參考下2019-03-03PHP實(shí)現(xiàn)將幾張照片拼接到一起的合成圖片功能【便于整體打印輸出】
這篇文章主要介紹了PHP實(shí)現(xiàn)將幾張照片拼接到一起的合成圖片功能,可實(shí)現(xiàn)多張圖片的合并,便于整體打印輸出.涉及php字符串、數(shù)組的遍歷、排序及圖片合成、裁剪、縮放等相關(guān)操作技巧,需要的朋友可以參考下2017-11-11jQuery+php實(shí)現(xiàn)ajax文件即時(shí)上傳的詳解
本篇文章是對(duì)jQuery+php實(shí)現(xiàn)ajax文件即時(shí)上傳的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06