本帖最后由 helloqhq 于 2011-04-06 10:42:41 编辑

解决方案 »

  1.   

    tom的已解决<?php
    /**
     * 获得tom邮箱通讯录列表 -- contactstom.class.php
     */
    define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限
    define( "TIMEOUT", 1000 ); //超时设定class contactstom
    { function checklogin( $user, $password )
    {
    $ch = curl_init( );
    curl_setopt( $ch, CURLOPT_URL, "http://login.mail.tom.com/cgi/login" );
    curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
    curl_setopt( $ch, CURLOPT_POST, 1 );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );
    curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
    $fileds = "user=".$user."&pass={$password}";
    $fileds .= "&style=0&verifycookie";
    $fileds .= "&type=0&url=http://bjweb.mail.tom.com/cgi/login2";
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $fileds );
    ob_start( );
    curl_exec( $ch );
    $str = curl_exec($ch); 
    // echo $str;exit;
    $result = ob_get_contents( );
    ob_end_clean( );
    curl_close( $ch );
    /*if ( preg_match( "/warning|?��??/", $result ) )
    {
    return 0;
    }*/
    return 1;
    } function getcontacts( $user, $password, &$result )
    {
    if ( !$this->checklogin( $user, $password ) )
    {
    return 'checklogin失败';
    }
    $this->readcookies( COOKIEJAR, $res );
    if ( $res['Coremail'] == "" )
    {
    return 'readcookies失败';
    }
    $sid = substr( trim( $res['Coremail'] ), -16 );
    $url = "http://bjapp2.mail.tom.com/cgi/ldvcapp";
    $url .= "?funcid=address&sid=".$sid."&showlist=all&listnum=0";
    $ch = curl_init( );
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );
    curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );
    curl_setopt( $ch, CURLOPT_COOKIEFILE, COOKIEJAR );
    ob_start( );
    curl_exec( $ch );
    $res = ob_get_contents( );

    ob_end_clean( );
    curl_close( $ch );

    $p="/<td\sclass=\"Addr_Td_Name\"><a href=\"(.+)?\">(.+)?<\/a><\/td><td\sclass=\"Addr_Td_Address\"><a\shref=\"(.+)?\">(.+)?<\/a>/";
    preg_match_all( $p, $res, $tmp);
    $result[0]=$tmp[2];

    $pattern = "/([\\w_-])+@([\\w])+([\\w.]+)/";
    if ( preg_match_all( $pattern, $res, $tmpres, PREG_PATTERN_ORDER ) )
    {
    $result[1] = array_unique( $tmpres[0] );
    }
    return $result;
    }

    function readcookies( $file, &$result )
    {
    $fp = fopen( $file, "r" );
    while ( !feof( $fp ) )
    {
    $buffer = fgets( $fp, 4096 );
    $tmp = split( "\t", $buffer );
    $result[trim( $tmp[5] )] = trim( $tmp[6] );
    }
    return 1;
    }}$contacts = new contactstom;$res = $contacts->getcontacts('****@tom.com','*****',$result);print_r($res);?>
      

  2.   

    别的都解决弄了,就差sohu、移动、联通三个的邮箱没有获取了,期待会的大侠相助ing。。
      

  3.   

    <?php
    /**
    * @file class.126http.php
    * 获得126邮箱通讯录列表
    * @author jvones<[email protected]> http://www.jvones.com/blog
    * @date 2009-09-26
    **/
    class http126
    {
           private function login($username, $password)
           {             
                //第一步:初步登陆
                $cookies = array();
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                
                curl_setopt($ch, CURLOPT_URL, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1");
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$username."@126.com&password=".$password);
                
                curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
                curl_setopt($ch,CURLOPT_HEADER,1);             
                curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $str = curl_exec($ch);       
                //file_put_contents('./126result.txt', $str);             
                curl_close($ch);
                         
                //获取redirect_url跳转地址,可以从126result.txt中查看,通过正则在$str返回流中匹配该地址
                preg_match("/replace\(\"(.*?)\"\)\;/", $str, $mtitle);
                $_url1 = $mtitle[1];
                
                //file_put_contents('./126resulturl.txt', $redirect_url);       
                //第二步:再次跳转到到上面$_url1
                $ch = curl_init($_url1);             
                
                curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
                curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);             
                curl_setopt($ch,CURLOPT_HEADER,1);       
                $str2 = curl_exec($ch);
                curl_close($ch);
                                                 
                if (strpos($contents, "安全退出") !== false)
                {                      
                         return 0;
                }             
                return 1;
           }
          
           /**
          * 获取邮箱通讯录-地址
          * @param $user
          * @param $password
          * @param $result
          * @return array
          */
           public function getAddressList($username, $password)
           {             
                if (!$this->login($username, $password))
                {
                         return 0;
                }
             
                $header = $this->_getheader($username);
                if (!$header['sid'])
           {
             return 0;
           }
          
           //测试找出sid(很重要)和host
           //file_put_contents('./host.txt', $header['host']);
           //file_put_contents('./sid.txt', $header['sid']);
          
                //开始进入模拟抓取
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "http://".$header['host']."/a/s?sid=".$header['sid']."&func=global:sequential");
                curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));
                $str = "<?xml version=\"1.0\"?><object><array name=\"items\"><object><string name=\"func\">pab:searchContacts</string><object name=\"var\"><array name=\"order\"><object><string name=\"field\">FN</string><boolean name=\"ignoreCase\">true</boolean></object></array></object></object><object><string name=\"func\">user:getSignatures</string></object><object><string name=\"func\">pab:getAllGroups</string></object></array></object>";
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
                curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
                ob_start();
                curl_exec($ch);
                $contents = ob_get_contents();            ob_end_clean();
                curl_close($ch);
                
           //get mail list from the page information username && emailaddress
           preg_match_all("/<string\s*name=\"EMAIL;PREF\">(.*)<\/string>/Umsi",$contents,$mails);
           preg_match_all("/<string\s*name=\"FN\">(.*)<\/string>/Umsi",$contents,$names);
           $users = array();
           foreach($names[1] as $k=>$user)
           {
             //$user = iconv($user,'utf-8','gb2312');
             $users[$mails[1][$k]] = $user;
           }
           if (!$users)
           {
             return '您的邮箱中尚未有联系人';
           }    
          
           return $users;
           }
          
           /**
    * Get Header info
    */
    private function _getheader($username)
    {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=".$username."@126.com");
                curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);   //当前使用的cookie
                curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR); //服务器返回的新cookie
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HEADER, true);
                curl_setopt($ch, CURLOPT_NOBODY, true);
                $content=curl_exec($ch);
                
                preg_match_all('/Location:\s*(.*?)\r\n/i',$content,$regs);
           $refer = $regs[1][0];
           preg_match_all('/http\:\/\/(.*?)\//i',$refer,$regs);             
           $host = $regs[1][0];
           preg_match_all("/sid=(.*)/i",$refer,$regs);
           $sid = $regs[1][0];
                
                curl_close($ch);
                return array('sid'=>$sid,'refer'=>$refer,'host'=>$host);
    }
    }?>
      

  4.   

    就差sohu、移动、联通的邮箱不能获取了,继续等待
      

  5.   

    就差sohu、移动、联通的邮箱不能获取了,继续等待
      

  6.   

    这个可以下载hao123这样的网站源码看看。导航类网站都有的。
      

  7.   

    本帖最后由 xuzuning 于 2011-07-19 17:47:36 编辑
      

  8.   

    楼主,希望你最好测试一下代码,比如tom的我就帮你测试了,如果是中文的联系人信息将会出现乱码,错误原因解决:iconv("gb2312", "utf-8",抓取的内容)。
    再有就是联系人列表中有的没有name,那么也容易导致错误,解决方案就是在错误处进行详细处理,比如name=邮箱@前面的字符串,因为这个在我做yahoo邮箱的时候有过错误,很容易导致用户名和邮箱不匹配。
    还有就是建议楼主把gmail加进去,毕竟这个很多人都用,而且gmail还有一点小的挑战性哦~
      

  9.   

    好久不来了,回复晚了,楼主的邮箱做好了吗?sohu的我已经做好并测试了,之前研究过邮箱的东西,感觉还是蛮好玩的,很乐意和你分享讨论。个人认为,邮箱中最难的是hotmail。
      

  10.   

    <?php
    /**
     * $obj->name 用户姓名
     * $obj->nickname 昵称
     * $obj->emailAddress email
     * 在UTF-8下已测试
     * 根据sohu邮箱特点,该邮箱不提供用户姓名,只提供用户昵称以及用户的昵称拼音,获取时昵称作为用户姓名,拼音作为昵称
     * 非汉字时,获取的拼音为空,因此昵称与姓名将保持一致
     * 当姓名为中文时显示中文,否则为英文,对于其他语种日文韩文已经测试成功无乱码
     * 测试输入接口为:getAddressList('[email protected]', 'password');
     */
    define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); 
    class sohu
    {
    public function getAddressList($username, $password)
    {       
    $name=explode('@', $username);
    $username=$name[0];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";

    curl_setopt($ch, CURLOPT_URL, $encodeurl);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR );
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $contents = curl_exec( $ch );

    if ( strpos( $contents, "success" ) === false )
    {
        return 0;
    }

    curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/99/main");
    $contents = curl_exec($ch);
        if(false !== $contents && '' != trim($contents)){ 
            curl_close( $ch );
         return $this->parserContent($contents);
        }
        
       curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/79/main#addressList");
       $contents = curl_exec($ch);
       if(false == $contents){ 
         curl_close( $ch );
            return false;
        }else{ 
            curl_close( $ch );
         return $this->parserContent($contents);
        }
    }
    function parserContent($content){
    preg_match_all("/var addresses = '(.*)';/Umsi",$content,$data);
    $numList= json_decode( $data[1][0]);
    $contactList = array();
    foreach ($numList->contact as $val){
    $obj = new stdClass;
    $obj->name = $val->nickname;
    $obj->nickname = $val->pinyin;
    $obj->emailAddress = $val->email; 
    if($obj->nickname==""){
    $obj->nickname = $obj->name;
    }
    $contactList[] = $obj; 
    }
    if( count($contactList) == 0 ){
    return false;
    }else{
    return $contactList;
    }
    }

    }$test = new sohu();
    $contects = $test->getAddressList('[email protected]', 'password');?>
      

  11.   

    能分享下你的详细思路吗?我之前试过,好像sohu邮箱登陆时要跳转多次,主要是session的连续获取和发送这块搞的有点晕,你最好在你的代码上加上详细的注释,分享下,你也加深下印象,也许会有新收获,呵呵!!!
      

  12.   

    好,那我就大概解释一下这个获取的过程。我不知道你用的什么浏览器,我用的是火狐的,有一个插件叫做firebug,专门用来跟踪脚本语言的,可以设置断点进行数据查看。
    搜狐的邮箱登陆界面,源码是这样写的:
    <form action="" name="form_login" onsubmit="return mydoLogin();">
        <input type="hidden" id="userid" name="userid" value="" />
    <input type="hidden" id="appid" name="appid" value="1000" />
    <input type="hidden" id="ru" name="ru" value="" />
    <ul>
        <li class="wrong" id="errorMsg">&nbsp;</li> <li>邮 箱:
      <input type="text" class="wid" id="username" name="username" tabindex="1" autocomplete="off" disableautocomplete/>
    </li>
    <div id="ppcard" style="position: absolute; padding-left:0px"> </div>
    <li>密 码:
      <input type="password" class="wid" id="password" name="password" tabindex="1"/><a href="http://passport.sohu.com/web/recover.jsp" target="_blank" class="pw">忘记密码</a></li>
    <li class="font12 mar"><input name="persistentcookie" id="rpwd" type="checkbox" value="1" tabindex="1"/><label for="rpwd">记住登录状态</label> 
    <span style="margin:0 0 17px 13px"><a href="https://mail.sohu.com?schemeforce=1" class="pw" title="从登录开始全程加密,让你的信息更安全。">https安全访问</a></span></li> <li class="mar">
    <input id="login_img" type="image" src="http://js.mail.sohu.com/images/index/button_login_new.gif" border="0" tabindex="1" />
    <span id="login_tip" style="display:none;">正在登录搜狐通行证,请稍候...</span>
    </li>
    <li class="now"><a href="http://passport.sohu.com/web/dispatchAction.action?appid=1000&ru=http://mail.sohu.com/reg/signup_success.jsp" target="_blank">
    <img src="http://js.mail.sohu.com/images/index/spacer.gif" width="56" height="20" border="0" class="cursor"/></a></li>
    </ul>
      </form>
    其中的<form action="" name="form_login" onsubmit="return mydoLogin();">调用的是mydoLogin函数,通过进行一些列跟踪不难获得最终有用的url地址(我的用firebug进行跟踪的):、
    {document.location.href="http://passport.sohu.com";return false}
    var A=getBrowserType();
    var B=screen.width;document.forms[C].action="http://passport.sohu.com/sso/login_js.jsp?appid="+this.appid+"&ru="+this.postru+"&b="+A+"&w="+B+"&v="+this.version;document.forms[C].submit();
    return false},
    doLogin:function(){if(this.eInterval){return }
    if(arguments[0]){PassportCardList[index].doLogin()}
    也就是实际上登录按钮提交以后,是这个页面(http://passport.sohu.com/sso/login_js.jsp?*****)来帮我们实现登录的,然后进行相关跳转的。
    那个sohu类的代码中有这样一行:
     $encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";
    我们完完全全可以在这里设置一个断点,获取得到$encodeurl(大概是这样的值:http://passport.sohu.com/sso/login.jsp?userid=username%40sohu.com&password=(urlencode处理过的密码)&appid=1000&persistentcookie=0&s=1310705795343&b=2&w=1024&pwdtype=1),然后把这个值放在浏览器的地址栏里回车,你就会发现网页刷新显示了“login_status='success';”这几个字,这时候说明你的登录已经结束了,现在在刷新一下搜狐登录界面会发现直接进入邮箱了,没错$encodeurl值已经帮你实现登录存储数据过程了。这时候在curl抓取任何信息都容易了。
    下面再分析一下我发的代码就应该容易理解一些了:
    <?php
    /**
     * $obj->name 用户姓名
     * $obj->nickname 昵称
     * $obj->emailAddress email
     * 在UTF-8下已测试
     * 根据sohu邮箱特点,该邮箱不提供用户姓名,只提供用户昵称以及用户的昵称拼音,获取时昵称作为用户姓名,拼音作为昵称
     * 非汉字时,获取的拼音为空,因此昵称与姓名将保持一致
     * 当姓名为中文时显示中文,否则为英文,对于其他语种日文韩文已经测试成功无乱码
     * 测试输入接口为:getAddressList('[email protected]', 'password');
     */
    define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) ); 
    class sohu
    {
    public function getAddressList($username, $password)
    {       
    $name=explode('@', $username);
    $username=$name[0];
    $ch = curl_init();
    //这个地址encodeurl就是刚才所说的那个可以帮助实现登录的地址
    $encodeurl = "http://passport.sohu.com/sso/login.jsp?userid=".urlencode($username . "@sohu.com") . "&password=".md5($password)."&appid=1000&persistentcookie=0&s=".time()."343&b=2&w=1024&pwdtype=1";

    curl_setopt($ch, CURLOPT_URL, $encodeurl);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR );
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $contents = curl_exec( $ch );

    if ( strpos( $contents, "success" ) === false )
    {
        return 0;
    }
        //由于已经记录了登录后的所有数据行为,因此只需看一下搜狐地址簿(就是联系人的链接地址),是http://mail.sohu.com/bapp/79/main#addressList
        //因此我们只需模拟一下这个页面就可很方便的抓取上面的相关信息
       curl_setopt($ch, CURLOPT_URL, "http://mail.sohu.com/bapp/79/main#addressList");
       $contents = curl_exec($ch);
       if(false == $contents){ 
         curl_close( $ch );
            return false;
        }else{ 
            curl_close( $ch );
         return $this->parserContent($contents);
        }
    }
    function parserContent($content){
    preg_match_all("/var addresses = '(.*)';/Umsi",$content,$data);
    $numList= json_decode( $data[1][0]);
    $contactList = array();
    foreach ($numList->contact as $val){
    $obj = new stdClass;
    $obj->name = $val->nickname;
    $obj->nickname = $val->pinyin;
    $obj->emailAddress = $val->email; 
    if($obj->nickname==""){
    $obj->nickname = $obj->name;
    }
    $contactList[] = $obj; 
    }
    if( count($contactList) == 0 ){
    return false;
    }else{
    return $contactList;
    }
    }

    }$test = new sohu();
    $contects = $test->getAddressList('[email protected]', 'password');?>
    不知道这么说你能否明白,很乐意一起讨论。之前在一个人人网API的帖子上面也看见你了,有经验的话也可以一起讨论,之前也有关研究人人、开心、facebook的api,不过不是很成熟,所以可以讨论。
      

  13.   

    public function update($table, $fields, $value, $where) {
      $fieldsStr = implode(' , ', $fields );
      $valueStr = implode(' , ', $value);
      $whereStr = implode (',', $where);
      $sql = 'UPDATE ' . $table . ' SET ' . $fieldsStr . ' = ' . $valueStr . 'WHERE ( ' . $whereStr . ' ) ';
    return mysql_query($sql);
    }
    这是我写的一个通用的更新数据的方法 更新多条怎么写!帮帮呢! 
      

  14.   

    谢谢分享,收获颇丰,我也是新手,之前抓取的时候,不知道怎么找主要的跳转url,也不知道怎么记录和传递cookie值,好像模拟登陆最主要的就是这两点了,这两点明白后,就一马平川了。原理是相同的,模拟登陆其它邮箱也用同样的方法。由于最近有活动要做,回复的不及时,还请见谅。
      

  15.   

    gmail <?php
    define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限
    define( "TIMEOUT", 1000 ); //超时设定
    class GMAIL
    {
        private function login($username, $password)
        {               
            //第一步:模拟抓取登录页面的数据,并记下cookies
            $cookies = array();
            $matches = array();
            //获取表单
            $login_url = "https://www.google.com/accounts/ServiceLoginAuth";
            $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('dsh','timeStmp','secTok'); 
            foreach($name as $v) {
                 preg_match('/<input\s*type="hidden"\s*name="'.$v.'"\s*id="'.$v.'"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
                if(!empty($matches)) {
                    $$v = $matches[1];
                    $matches = array();
                }        
            }
            $server = 'mail';
            preg_match('/<input\s*type="hidden"\s*name="GALX"\s*value="(.*?)"\s*\/>/i', $contents, $matches);
            
            if(!empty($matches)) 
            {
                $GALX = $matches[1];
                $matches = array();
            } 
            $timeStmp = time();
            
            //第二步: 开始登录
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginAuth");
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR); 
            curl_setopt($ch, CURLOPT_POST, 1);
            $fileds = "dsh=$dsh&Email=".$username."&Passwd={$password}&GALX=$GALX&timeStmp=$timeStmp&secTok=$secTok&signIn=Sign in&rmShown=1&asts=&PersistentCookie=yes"; 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fileds); 
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);              
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $str = curl_exec($ch);               
            curl_close($ch);        //第三步:check Cookies即也算是个引导页面
            $ch = curl_init("https://www.google.com/accounts/CheckCookie?chtml=LoginDoneHtml");
           
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch,CURLOPT_COOKIEFILE,COOKIEJAR);
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);                 
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);     
            $str2 = curl_exec($ch);
             
            curl_close($ch);
                                            
            if (strpos($contents, "安全退出") !== false)
            {                        
             return FALSE;
            }               
            return TURE;
        }
        
        /**
         * 获取邮箱通讯录-地址
         * */
        public function getAddressList($username, $password)
        {               
            if (!$this->login($username, $password))
            {
                return FALSE;
            }
            //开始进入模拟抓取
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://mail.google.com/mail/contacts/data/contacts?thumb=true&groups=true&show=ALL&enums=true&psort=Name&max=300&out=js&rf=&jsx=true");  //out=js返回json数据,不设置返回为xml数据   
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
            curl_setopt($ch, CURLOPT_POST, 1);       
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            $contents = curl_exec($ch);
            curl_close($ch);        $contents = substr($contents, strlen('while (true); &&&START&&&'),  -strlen('&&&END&&& ')); 
            return $contents;
        }
    }$gamil = new GMAIL;$res = $gamil->getAddressList('****@gmail.com','****');$a = json_decode($res);echo "<pre>";
    //print_r($a->Body->Contacts);
    foreach($a->Body->Contacts as $k=>$v)
    {
    echo "姓名:".$v->DisplayName;
    echo "家庭email:".$v->Emails[0]->Address;
    echo "工作email:".$v->Emails[1]->Address;
    echo "<br>";
    }
    echo "</pre>";?>
      

  16.   

    hotmail<?php
    define( "COOKIEJAR", tempnam( ini_get( "upload_tmp_dir" ), "cookie" ) );   //定义COOKIES存放的路径,要有操作的权限
    define( "TIMEOUT", 1000 ); //超时设定
    class MSN
    {
        function getAddressList($username, $password)
        {               
            //第一步:模拟抓取登录页面的数据,并记下cookies
            $cookies = array();
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_URL, "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=".time()."&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=en");
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $str = curl_exec($ch);              
            curl_close($ch);        //参数的分析
            $matches = array();       
            preg_match('/<input\s*type="hidden"\s*name="PPFT"\s*id="(.*?)"\s*value="(.*?)"\s*\/>/i', $str, $matches); 
            $PPFT = $matches[2];
            
            preg_match('/srf_sRBlob=\'(.*?)\';/i', $str, $matches); 
            $PPSX = $matches[1];
            
            $type = 11;
            $LoginOptions = 3;
            $Newuser = 1;
            $idsbho = 1;
            $i2 = 1;
            $i12 = 1;
            $i3 = '562390';
            $PPSX = 'Pa';
            /* 合并参数 */
            $postfiles = "login=".$username."&passwd=".$password."&type=".$type."&LoginOptions=".$LoginOptions."&Newuser=".$Newuser."&idsbho=".$idsbho."&i2=".$i2."&i3=".$i3."&PPFT=".$PPFT."&PPSX=".$PPSX."&i12=1";        /* 第二步:开始登录 */
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
            curl_setopt($ch, CURLOPT_URL, 'https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct='.(time()+5).'&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2052&id=64855&mkt=en&bk='.(time()+715)); //此处的两个time()是为了模拟随机的时间            
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postfiles);
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        $content = curl_exec($ch);
            curl_close($ch);        if( stripos($content,'WLWorkflow') !== FALSE ) {     //WLWorkflow登录页面JS
                return false;      //登录失败
            }
            /* 获取location链接 */
            $matches = array();       
            preg_match('/window.location.replace\(\"(.*?)\"\)/i', $content, $matches); 
            $url_contiune_1 = $matches[1]; //接下来的链接
            if(!$url_contiune_1) 
            {
                return false;
            }
            /* 第三步: 进入引导页面 */
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
            curl_setopt($ch, CURLOPT_URL, $url_contiune_1);
            curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
            curl_setopt($ch, CURLOPT_HEADER, 1); 
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $content_2 = curl_exec($ch);
            
            curl_close($ch);
            
            /* 获取redicturl链接 */
            $matches = array();       
            preg_match('/<a\s*href=\"(.*?)\"\s*>/i', $content_2, $matches); 
            $url_contiune_2 = $matches[1]; //接下来的链接
            if(!$url_contiune_2) 
            {
                return false;
            }
            
            /* 获取邮箱请求基址 读取host */
            $matches = array();       
            preg_match('/(.*?)\/\/(.*?)\/(.*?)/i', $url_contiune_2, $matches); 
            $url_contiune_3 = trim($matches[1]).'//'.trim($matches[2]); //首页定义的站点基址
            $url_4 = $url_contiune_3.'/mail/ContactMainLight.aspx?n=435707983'; //n后面的数字是随机数
            if(!$url_contiune_3) 
            {
                return false;
            }
            
            /* 第四步: 开始获取邮箱联系人 */
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
            curl_setopt($ch, CURLOPT_URL, $url_4);
            curl_setopt($ch, CURLOPT_TIMEOUT, TIMEOUT);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $str = curl_exec($ch);
            /* 分析数据 (此处的数据因为hotmail的JS处理机制,所以在页面上看不出来,源码上可以看到数据) */
            return $this->hanlde_date($str);
                
        }
        
        function hanlde_date($data) 
        {
            $new_str = array();
            if(!empty($data)) 
            {
                $ops_start = stripos($data,'ic_control_data');
                $ops_end = stripos($data,';',$ops_start);
                $new_str = substr($data, $ops_start + strlen('ic_control_data = '), $ops_end - $ops_start - strlen('ic_control_data = ') );
                return $new_str; //返回JSON对象
            }
            else 
            {
                return array();
            }                         
        }
    }$msn = new MSN;//$res = $msn->getAddressList('[email protected]','a000000');
    $res = $msn->getAddressList('[email protected]','88888');echo "<pre>";
    //print_r(json_decode($res, true)); 
    $a = json_decode($res, true);
    unset($a['icTmConvTemplate']);
    unset($a['icTmInlineTemplate']);
    unset($a['icTmTabInlineTemplate']);
    //print_r($a);
    foreach($a as $k=>$v)
    {
    echo "姓名:".$v[3];
    echo "  email:".$v[6];
    echo "<br>";
    }
    echo "</pre>";
    ?> 
      

  17.   

    楼主没少下功夫啊~支持~可是不知道过多久这些代码中的很多可能又要不能用了,然后大家又要重新研究如何抓取页面了,也许这就是各种email目前的不足之处吧。当所有的email都能有一个完整的并定期维护的API供大家使用时,Email的用处可以得到更广的使用,否则迟早会被某些新概念新技术所掩盖。google、gmail、yahoo已经都开始有了,国内的网易什么的都没动静啊……
      

  18.   

    这些也是我从网上找到的,还没有真正下功夫,以后肯定要摸透这个知识点,至于邮箱的联系人api,以后肯定都会支持的,国内的需要时间来跟随
      

  19.   

    感谢几位的分享....终于搞定了sohu邮箱的了....我也是新手...内牛满面....现在的要将"http://mail.sohu.com/bapp/79/main#addressList"
    改为
    "http://mail.sohu.com/bapp/117/main#addressList"
    了...希望也对后面的同志有帮助