<?php
define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); //定义COOKIES存放的路径,要有操作的权限
define( "TIMEOUT", 1000 ); //超时设定
class YAHOO
{
private function login($username, $password)
{
//第一步:模拟抓取登录页面的数据,并记下cookies
$cookies = array();
$matches = array();
//获取表单
$login_url = "https://login.yahoo.com/config/login?.src=fpctx&.intl=us&.done=http%3A%2F%2F%2F";
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
//构造参数
$name = array('tries','src','md5','hash','js','last','promo','intl','bypass','partner','u','v','challenge','yplus','emailCode','pkg','stepid','ev','hasMsgr','chkP','done','pd','pad','aad');
$postfiles = array();
$matches = array();
foreach($name as $v) {
preg_match('/<input/s*type="hidden"/s*name=".'.$v.'"/s*value="(.*?)"/s*>/i', $contents, $matches);
if(!empty($matches)) {
$postfiles['.'.$v] = $matches[1];
$matches = array();
}
if($v == 'pd') {
$postfiles['.'.$v] = urlencode($postfiles['.'.$v]);
}
}
$postfiles['pad'] = 5;
$postfiles['aad'] = 6;
$postfiles['login'] = urlencode($username);
$postfiles['passwd'] = $password;
$postfiles['.persistent'] = 'y';
$postfiles['save'] = '';
$postfiles['.done'] = urlencode($postfiles['.done']);
//$postfiles['.pd'] = urlencode($postfiles['.pd']);
$postargs = '';
foreach($postfiles as $k => $v){
$postargs .= $k.'='.$v.'&';
}
$postargs = substr($postargs,0,-1);
$request = "https://login.yahoo.com/config/login?";
//开始登录
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
curl_close($ch);
if (stripos($contents,'submit') != FALSE)
{
return 0;
}
return 1;
}
//获取邮箱通讯录-地址
public function getAddressList($username, $password)
{
if (!$this->login($username, $password))
{
return 0;
}
//开始进入模拟抓取
//get mail list from the page information username && emailaddress
$url = "http://address.mail.yahoo.com/";
$data = array( );
if ( !$data = $this->hanlde_date( $url, $names, $emails) )
{
return FALSE;
}
echo '<pre>';
print_r($data);
return $data;
}
function hanlde_date( $url, &$names, &$emails)
{
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
curl_close($ch);
$temparr = array();
preg_match_all('/InitialContacts/s*=https://www.jb51.net/s*(.*?);/i',$contents,$temparr);
return $temparr[1][0].';'; //匹配出JSON对象数组
}
}
$yahoo = new YAHOO;
$res = $yahoo->getAddressList('username@yahoo.com.cn','123456');
?>
<mce:script type="text/javascript"><!--
var data = <?php echo $res; ?>
var obj1 = data[0];
alert(data[0]['contactName']);
// --></mce:script>
注:
163,126在网上的源码都有,在此就不一一的列出来了哦
当然此代码是自己个人的拙作,只是为了给大家此类问题做一个指引
您可能感兴趣的文章: