首页 php教程 PHP开发 php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)

php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)

Dec 30, 2016 am 10:20 AM

CURL技术说白了就是模拟浏览器的动作实现页面抓取或表单提交,通过此技术可以实现许多有去的功能。

<?php 
error_reporting(0); 
//邮箱用户名(不带@163.com后缀的) 
$user = &#39;papatata_test&#39;; 
//邮箱密码 
$pass = &#39;000000&#39;; 
//目标邮箱 
//$mail_addr = uenucom@163.com&#39;; 
//登陆 
$url = &#39;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&#39;; 
$ch = curl_init($url); 
//创建一个用于存放cookie信息的临时文件 
$cookie = tempnam(&#39;.&#39;,&#39;~&#39;); 
$referer_login = &#39;http://mail.163.com&#39;; 
//返回结果存放在变量中,而不是默认的直接输出 
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( 
&#39;username&#39;=> $user, 
&#39;password&#39;=> $pass, 
&#39;verifycookie&#39;=>1, 
&#39;style&#39;=>-1, 
&#39;product&#39;=> &#39;mail163&#39;, 
&#39;selType&#39;=>-1, 
&#39;secure&#39;=>&#39;on&#39; 
); 
$headers_login = array( 
&#39;User-Agent&#39; => &#39;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0&#39;, 
&#39;Referer&#39; => &#39;http://www.163.com&#39; 
); 
$fields_string = &#39;&#39;; 
foreach($fields_post as $key => $value) 
{ 
$fields_string .= $key . &#39;=&#39; . $value . &#39;&&#39;; 
} 
$fields_string = rtrim($fields_string , &#39;&&#39;); 
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=&#39;http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=loki_wuxi&#39;; 
$ch = curl_init($url); 
$headers = array( 
&#39;User-Agent&#39; => &#39;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0&#39; 
); 
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(&#39;/sid=[^\"].*/&#39;, $result, $location); 
$sid = substr($location[0], 4, -1); 
//file_put_contents(&#39;./result.txt&#39;, $sid); 
//通讯录地址 
$url=&#39;http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid=&#39;.$sid.&#39;&gid=all&#39;; 
$ch = curl_init($url); 
$headers = array( 
&#39;User-Agent&#39; => &#39;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0&#39; 
); 
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(&#39;./result.txt&#39;, $result); 
unlink($cookie); 
//开始抓取内容 
preg_match_all(&#39;/<td class="Ibx_Td_addrName"><a[^>]*>(.*?)<\/a><\/td><td class="Ibx_Td_addrEmail"><a[^>]*>(.*?)<\/a><\/td>/i&#39;, $result,$infos,PREG_SET_ORDER); 
//1:姓名2:邮箱 
print_r($infos); 
?>
登录后复制

更多php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)相关文章请关注PHP中文网!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)