时间:2021-07-01 10:21:17 帮助过:4人阅读
function file_get($url){ ob_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; CIBA)"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_exec($ch); curl_close($ch); $content = ob_get_clean(); return $content;}
请加一句代码:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
因为你抓取http://map.sogou.com/api,他返回的是301跳转。加上这句就能抓取跳转后的html了。
请加一句代码:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
因为你抓取http://map.sogou.com/api,他返回的是301跳转。加上这句就能抓取跳转后的html了。
加上也不行,还是无法获取
请加一句代码:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
因为你抓取http://map.sogou.com/api,他返回的是301跳转。加上这句就能抓取跳转后的html了。
加上也不行,还是无法获取
function file_get($url){ ob_start(); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookie.txt"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1; CIBA)"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,TRUE); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_exec($ch); curl_close($ch); $content = ob_get_clean(); return $content;}
CURLOPT_FOLLOWLOCATION