PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

原创
2016-06-13 11:36:24 672浏览

求高手,模拟浏览器抓取网页
如抓取http://map.sogou.com/api/这个网页,我写的程序,如果不带网址后面的"//m.sbmmt.com/m/",会抓取得不到,但是站上网(http://tool.chinaz.com/Tools/PageCode.aspx),不带最后面的"//m.sbmmt.com/m/"即可抓取到(即: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;

}
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。