我之前做过qq和新浪邮箱的登陆。
天涯的登陆比较特殊:post密码、账号后,在返回的页面里用js设置cookie(这里的cookie我都获取到了),返回的页面里有
3个script估计是用于单点登陆的,然后做了一个js跳转到my.tianya.cn,返回的页面又做了一个js跳转,分别创建了3份cookie,但是最后登陆的时候还是不行。
讲也没办法讲很清楚
有谁做过成功的没

解决方案 »

  1.   

    我模拟post密码和账号后只得到了一个sessionid,其他的cookie都是用js设置,那么在服务器估计只是判断提交的sessionid是否符合,符合的话就直接操作客户端传送过来cookie,因为貌似服务器没有设置其它数据的session了
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <base href="http://passport.tianya.cn:80/" />
    <!--  <meta http-equiv="refresh" content="2;URL=http://my.tianya.cn/"/>--><title>登录中......</title>

    <script>
    document.cookie='user=w=用户名&id=47317780&f=1;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp=k=685683557&s=&t=1295507094&b=8c2375a263bd1826a2ed402abd915446&ct='+parseInt(new Date().getTime()/1000)+';expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='sso=r=1975164433&sid=D714B1EDA76BB89465410F5D51C8320B&wsid=7A3EE0B833B0E3C08C39AE4FB246CFC9;expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='right=web4=n&portal=n;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp4=rm=;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    </script> <script type="text/javascript" src="http://passport.tianyaclub.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=tianyaclub.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
    <script type="text/javascript" src="http://passport.hainan.net/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hainan.net&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
    <script type="text/javascript" src="http://passport.hiholiday.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hiholiday.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>

    </head><body>
    <!--

    <form  name="buffer" action="http://my.tianya.cn/" method="post">
    -->
    <script >


    location.href="http://my.tianya.cn/";

    //document.buffer.submit();
    //location.href="http://my.tianya.cn/";
    var url="http://my.tianya.cn/";
    function jump(url){
         var e = document.createElement("a");
         e.href = url;
         document.body.appendChild(e);
         e.click();
    }

    </script>

    <!-- </form>-->

    </body></html>这是post密码和账号之后返回的页面,里面用js设置的cookie我也获取到了,然后再次模拟登陆http://my.tianya.cn/ ,然后再次模拟登陆http://my.tianya.cn/userid...然后var_dump返回的结果但是结果页面显示的是未登录的。因为页面仍然出现登陆,注册按钮
      

  3.   


    <?php
    class TianYaBlog{
    private $loginUrl='http://passport.tianya.cn/login';
    private $homeUrl = 'http://my.tianya.cn';
    private $publishUrl;
    private $postUrl;
    private $ch;
    private $userId;
    private $pwd='密码';
    private $acc = '用户名';
    private $cookie_file;//='D:\VertrigoServ\www\ty.txt';
    function __construct(){
    $this->cookie_file = tempnam('/tmp','ty');
    }
    function register(){

    }
    function getHomeCookie(){
    $this->ch = curl_init();
    curl_setopt($this->ch,CURLOPT_URL,$this->homeUrl);
    curl_setopt($this->ch,CURLOPT_POST,TRUE);
    curl_setopt($this->ch,CURLOPT_REFERER,'http://my.tianya.cn');
    curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($this->ch,CURLOPT_HEADER,TRUE);
    curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
    $con = curl_exec($this->ch);
    curl_close($this->ch);
    var_dump($con);
    }
    function Login(){
    $this->ch = curl_init();
    curl_setopt($this->ch,CURLOPT_URL,$this->homeUrl);
    curl_setopt($this->ch,CURLOPT_POST,TRUE);
    curl_setopt($this->ch,CURLOPT_REFERER,'http://my.tianya.cn');
    curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($this->ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    curl_setopt($this->ch,CURLOPT_COOKIEJAR,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_COOKIEFILE,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
    $con = curl_exec($this->ch);
    curl_close($this->ch);
    // return;
    //$con = preg_replace('/(>)([\s\S]*?)(<\/script>)/i',"\${1}window.location.href='http://my.tianya.cn/".$this->userId."'\$3",$con);
    //var_dump($con);exit();
    $this->ch = curl_init();
    curl_setopt($this->ch,CURLOPT_URL,$this->homeUrl.'/'.$this->userId);
    curl_setopt($this->ch,CURLOPT_REFERER,'http://my.tianya.cn');
    curl_setopt($this->ch,CURLOPT_HEADER,TRUE);
    curl_setopt($this->ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($this->ch,CURLOPT_COOKIEJAR,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_COOKIEFILE,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
    $con = curl_exec($this->ch);
    curl_close($this->ch);
    // var_dump($con);
    }
    function initCookie(){
    $this->ch = curl_init();
    curl_setopt($this->ch,CURLOPT_URL,$this->loginUrl);
    curl_setopt($this->ch,CURLOPT_POST,TRUE);
    curl_setopt($this->ch,CURLOPT_REFERER,'http://my.tianya.cn');
    curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($this->ch,CURLOPT_HEADER,TRUE);
    curl_setopt($this->ch,CURLOPT_POSTFIELDS,'vpassword='.$this->pwd.'&vwriter='.$this->acc.'&forwardUrl='.urlencode('http://my.tianya.cn/').'&returnUrl='.urlencode('http://my.tianya.cn/'));
    curl_setopt($this->ch,CURLOPT_COOKIEJAR,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_COOKIEFILE,$this->cookie_file);
    curl_setopt($this->ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
    curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
    $con = curl_exec($this->ch);
    curl_close($this->ch);
    //return;
    preg_match_all("/document.cookie=(.*?)\n/",$con,$match);
    $lcon = file_get_contents($this->cookie_file);
    //$lcon = preg_replace('/passport.tianya.cn/i','.tianya.cn',$lcon);
    foreach($match[1] as $val){
    $rs = explode(';',$val);
    $v1 = explode('=',$rs[0]);
    $v2 = substr($rs[0],strlen($v1[0])+1);
    if($v1[0]=="'user"){
    preg_match('/id=(.*?)&/',$v2,$match);
    $this->userId = $match[1];
    }
    if($v1[0]=="'temp"){
    $v2 = substr($v2,0,strrpos($v2,"=")+1).time();
    }
    $lcon .= "\r\n.my.tianya.cn TRUE / FALSE 0 ".substr($v1[0],1).' '.$v2;
    }
    file_put_contents($this->cookie_file,$lcon);
    return ; 
    preg_match_all("/src=\"(.*?)\"/",$con,$match);
    foreach($match[1] as $key=>$val){
    $this->ch = curl_init();
    curl_setopt($this->ch,CURLOPT_URL,$this->loginUrl);
    curl_setopt($this->ch,CURLOPT_POST,TRUE);
    curl_setopt($this->ch,CURLOPT_REFERER,'http://my.tianya.cn');
    curl_setopt($this->ch,CURLOPT_COOKIEJAR,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_COOKIEFILE,$this->cookie_file);
    curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
    $con = curl_exec($this->ch);
    curl_close($this->ch);
    }
    }
    function publish(){
    }
    }
    $c = new TianYaBlog();
    //$c->getHomeCookie();
    $c->initCookie();
    $c->Login();?>哈哈,终于有人肯来搭话了
      

  4.   

    呵呵其实已经登录成功了,直接操作想要的url就可以了,页面仍然显示登录按钮的原因应该是因为后来它是用js动态替换掉的,就是用js判断用户信息然后在去替换掉dom。我在html里有看到类似这样功能的函数。
    我试着操作博客的url,可以显示,证明是登录成功了~
      

  5.   

    楼主还在吗?我登陆后返回的HTML跟您2楼得一摸一样,但是没有返回COOKIE,请问下一步该怎么做?我试着把JS拼成字符串,当成COOKIE,好像不好使,请问对不对?
     <script>
    document.cookie='user=w=用户名&id=47317780&f=1;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp=k=685683557&s=&t=1295507094&b=8c2375a263bd1826a2ed402abd915446&ct='+parseInt(new Date().getTime()/1000)+';expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='sso=r=1975164433&sid=D714B1EDA76BB89465410F5D51C8320B&wsid=7A3EE0B833B0E3C08C39AE4FB246CFC9;expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='right=web4=n&portal=n;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp4=rm=;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    </script>
    ---------
    <script type="text/javascript" src="http://passport.tianyaclub.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=tianyaclub.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        <script type="text/javascript" src="http://passport.hainan.net/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hainan.net&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        <script type="text/javascript" src="http://passport.hiholiday.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hiholiday.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        
    这3个URL需要请求么?我请求过,好像都有COOKIE,但是还是不好使。总是登陆不成功,请指点该怎么做?
      

  6.   

    楼主还在吗?我登陆后返回的HTML跟您2楼得一摸一样,但是没有返回COOKIE,请问下一步该怎么做?我试着把JS拼成字符串,当成COOKIE,好像不好使,请问对不对?
     <script>
    document.cookie='user=w=用户名&id=47317780&f=1;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp=k=685683557&s=&t=1295507094&b=8c2375a263bd1826a2ed402abd915446&ct='+parseInt(new Date().getTime()/1000)+';expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='sso=r=1975164433&sid=D714B1EDA76BB89465410F5D51C8320B&wsid=7A3EE0B833B0E3C08C39AE4FB246CFC9;expires='+(new Date(new Date().getTime()+28800*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='right=web4=n&portal=n;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    document.cookie='temp4=rm=;expires='+(new Date(new Date().getTime()+2592000*1000)).toGMTString()+';path=/;domain=tianya.cn';
    </script>
    ---------
    <script type="text/javascript" src="http://passport.tianyaclub.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=tianyaclub.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        <script type="text/javascript" src="http://passport.hainan.net/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hainan.net&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        <script type="text/javascript" src="http://passport.hiholiday.com/domain.jsp?cookieTime=1295507094&portalValue=&rightCookie=false&rmCookieCode=&isActivatedUser=&idWriter=47317780&writer=imbigsnake1&intKey=685683557&chvSysGradeList=&sysGrade=&domain=hiholiday.com&flag=660b3f51149f6033665971af804ee8d9&rmCode=false"></script>
        
    这3个URL需要请求么?我请求过,好像都有COOKIE,但是还是不好使。总是登陆不成功,请指点该怎么做?