php curl 功能简介与抓取163邮件列表

来源:互联网 发布:java 唤醒指定线程 编辑:程序博客网 时间:2024/04/30 03:23
http://hi.baidu.com/sjow001/item/f3fda20e56cbc0c675cd3cef

error_reporting(0);

//邮箱用户名(不带@163.com后缀的)
$user       = '*********';
//邮箱密码
$pass       = '*********';
//目标邮箱
//$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('/]*>(.*?)<\/a><\/td>]*>(.*?)<\/a><\/td>/i', $result,$infos,PREG_SET_ORDER);
//1:姓名2:邮箱
print_r($infos);

/*
* 下面就可以为所欲为了- -
*/
?>


<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(1547) | 评论(0) | 转发(2) |
0

上一篇:curl命令

下一篇:linux下为php添加curl扩展的方法

相关热门文章
  • 关于SSI
  • IP Sec VPN与NAT破镜重圆
  • JS模拟鼠标自动点击
  • UT2.0正式版下载
  • tomcat6.0配置(含配置视频下载...
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~