php 利用cookie登录豆瓣采集内容
function Curl_get($url,$data = null){
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';
$curl = curl_init();
curl_setopt($curl, CURLOPT_COOKIE, '{这里您自己的cookie}');//Cookie值
//curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);//Cookie值
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,30);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $user_agent);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_REFERER, $ref);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
这样就可以采集豆瓣内容了!
相关推荐
标签:
留言与评论(共有 0 条评论) |