PHP curl爬取数据 加入cookie值

    public function get_cookie(){
        header("Content-type:text/html;Charset=utf8");
        $ch =curl_init();
        curl_setopt($ch,CURLOPT_URL,'爬取网址');
        $header = array();
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch,CURLOPT_HEADER,true);
        curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
        curl_setopt($ch,CURLOPT_COOKIE,'需要设置的cookie值');
        $content = curl_exec($ch);
        echo "<pre>";print_r(curl_error($ch));echo "</pre>";
        echo "<pre>";print_r(curl_getinfo($ch));echo "</pre>";
        echo "<pre>";print_r($header);echo "</pre>";
        echo "</br>",$content;
    }

posted @ 2017-11-27 18:04  宁佳兵  阅读(711)  评论(0编辑  收藏  举报