Yahoo 邮箱模拟登陆
[code="java"]/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 '
';
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*=\s*(.*?);/i',$contents,$temparr);
return $temparr[1][0].';'; //匹配出JSON对象数组
}
}
$yahoo = new YAHOO;
$res = $yahoo->getAddressList('username@yahoo.com.cn','123456');
?>
[/code]