2
回答
why not 自动登录百度 httpclient,snoopy
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
浏览器能记住百度登录状态,自动登录,为什么同样的header(也包括cookie)放在httpclien、snoopy上就登录不了了呢?这是什么原因导致的?如何解决
举报
chworld
发帖于3年前 2回/717阅
共有2个答案 最后回答: 3年前

引用来自“Gillian_Male”的评论

怎么证明记录不了?

写个程序验证下啊。

$snoopy=new \Snoopy();
        //设置snoopy,登录并且获取百度信息
        $uri="http://www.baidu.com/index.php?tn=monline_5_dg";
        // need an proxy?
//        $snoopy->proxy_host = "";
//        $snoopy->proxy_port = "";

        // set browser and referer:
        $snoopy->agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36";
        $snoopy->referer = "http://start.firefoxchina.cn/";
$cookies="BAIDUID=9EB08CA005C98EB7E75E11B:FG=1; BDUSS=Q2OGFKOGwzUGxmcjRAkdBTRW; BD_UPN=133143; BDRCVFR[kpkBv0s1F-3]=G01CoNuzfuh-zuyuEXApy49QhP8";
$splice=explode(";",$cookies);
        foreach($splice as $key=>$value){
            $map=explode("=",$value);
            if(sizeof($map)==2){
//                $cookieArray[$map]=$map;
                // set some cookies:
                $snoopy->cookies[$map]=$map;
            }else{
//                $cookieArray[$map]=$map."=".$map;
                // set some cookies:
                $snoopy->cookies[$map]=$map."=".$map;
            }
        }

$snoopy->rawheaders["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
        $snoopy->rawheaders["Accept-Encoding"] = "gzip,deflate";
        $snoopy->rawheaders["Accept-Language"] = "zh-CN,zh;q=0.8";
        $snoopy->rawheaders["Cache-Control"] = "max-age=0";
        $snoopy->rawheaders["Connection"] = "keep-alive";
        $snoopy->rawheaders["host"] = "www.baidu.com";

        // set some internal variables:
        $snoopy->maxredirs = 2;
        $snoopy->offsiteok = false;
        $snoopy->expandlinks = false;
        $snoopy->read_timeout=3;  //读取超时时间

        // set username and password (optional)
        //$snoopy->user = "joe";
        //$snoopy->pass = "bloe";

        // fetch the text of the website www.google.com:
        if($snoopy->fetchtext($uri)){







顶部