---
title: "Yahoo 邮箱模拟登陆"
author: "lcffufly"
date: "2012-01-14T17:28:44Z"
tags: []
categories: ["编程语言"]
slug: "yahoo"
draft: false
lastmod: "2012-01-14T17:28:44Z"
id: 1345402
url: "https://lcffufly.iteye.com/blog/1345402"
---

\[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 =&gt; $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-&gt;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-&gt;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]
```