<?
php error_reporting ( 0 );
set_time_limit ( 0 );
header ( "Content-Type: text/html; charset=GB2312" );
//邮箱用户名密码
$user = 'username';
$pass = 'password';
//创建一个文件用于存放cookie信息
define ( "COOKIEJAR", tempnam ( ini_get ( "upload_tmp_dir" ), "cookie" ) );
$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';
$refer = 'http://mail.163.com';
$fields_post = array ('username' => $user, 'password' => $pass, 'verifycookie' => 1, 'style' => - 1, '
product' => 'mail163', 'selType' => - 1, 'secure' => 'on' );
$fields_string = http_build_query ( $fields_post, '&' );
$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' );
//登录
$ch = curl_init ( $url );
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, $refer );
curl_setopt ( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt ( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
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';
$headers = array ('User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0' );
$ch = curl_init ( $url );
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, COOKIEJAR );
curl_setopt ( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
$result = curl_exec ( $ch );
curl_close ( $ch );
//取得sid
preg_match ( '/sid=[^/"].*/', $result, $location );
$sid = substr ( $location [0], 4, - 1 );
//通讯录地址
$url = 'http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid=' . $sid . '&gid=all';
$headers = array ('User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0' );
$ch = curl_init ( $url );
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, COOKIEJAR );
curl_setopt ( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
$result = curl_exec ( $ch );
curl_close ( $ch );
unlink ( COOKIEJAR );
//开始抓取内容
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 );
?>
/*
*判断一个url是否为有效链接
*/
function isRealUrl($url){
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true
);
curl_setopt_array($ch, $options);
curl_exec($ch);
if(!curl_errno($ch)){
return 200==curl_getinfo($ch,CURLINFO_HTTP_CODE)?true:false;
}
curl_close($ch);
}
$url = 'http://testpic1.tomoimg.cn/240x180/394/855/517932781/200901/12312215602409.jpg';
if(isRealUrl($url)){echo 'yes';}else{echo 'no';}
/异步请求的例子:
$userid = 517932781;
$imageid = 1520;
$albumid = 2637;
$tags = 'aa';
extract($_POST);
$url = 'http://'.$_SERVER['HTTP_HOST'].'/
ajax/image.php';
$fields = array(
'userid' => $userid,
'imageid' => $imageid,
'albumid' => $albumid,
'tags' => $tags,
'optype' => 'del'
);
$ch = curl_init() ;
curl_setopt($ch, CURLOPT_URL,$url) ;
curl_setopt($ch, CURLOPT_POST,true) ;
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields) ;
$result = curl_exec($ch) ;
curl_close($ch) ;
//上传文件
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://lh.tom.com/deal/import.php');
$fields = array(
'tname' => '道德经',
'country' => 1,
'author' => '老子',
'tags' => '道德经',
'desc' => '道可道,非常道。名可名,非常名。无名天地之始。有名万物之母。故常无欲以观其妙。常有欲以观其徼。此两者同出而异名,同谓之玄。玄之又玄,众妙之门。',
'volume' => 2,
'cover' => '@'.realpath('/data/lianhuanhua/deal/1.jpg')
);
curl_setopt($ch, CURLOPT_POST, true) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
$result = curl_exec($ch);
curl_close($ch);
//多文件上传
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://lh.tom.com/deal/addpic.php');
$j = 0;
$fields = array(
'vid' => 103,
'upfile['.$j++.']' => '@'.realpath('/data/lianhuanhua/deal/1.jpg'),
'upfile['.$j++.']' => '@'.realpath('/data/lianhuanhua/deal/2.jpg')
);
curl_setopt($ch, CURLOPT_POST, true) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
$result = curl_exec($ch);
curl_close($ch);