您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

求高手,模拟浏览器抓取网页

2024/3/1 23:36:03发布19次查看
如抓取http://map.sogou.com/api/这个网页,我写的程序,如果不带网址后面的/,会抓取得不到,但是站上网(http://tool.chinaz.com/tools/pagecode.aspx),不带最后面的/即可抓取到(即:http://map.sogou.com/api),他是什么原理?下面贴出我的代码,请改进
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
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product