Home >Backend Development >PHP Tutorial > 怎么抓取google结果跟浏览器一样

怎么抓取google结果跟浏览器一样

WBOY
WBOYOriginal
2016-06-13 13:18:23879browse

如何抓取google结果跟浏览器一样
本人使用的是php curl扩展函数进行的google关键字抓取页面数据,但是添加了header什么的抓取返回的页面结果还是跟浏览器的不一致。

所以跪求哪位高人能够告诉下,如何才能够让我的程序抓取获得的页面结果跟浏览器显示的页面结果一致。

谢谢

只有20分,希望高手能够见谅。

------解决方案--------------------
像这样,url地址你自己换吧。

PHP code
header("Content-type: text/html; charset=utf-8");
$ch = curl_init();
$url = 'http://www.google.com/search?hl=zh-CN&biw=1366&bih=649&q=ajax&oq=ajax+comment&aq=f&aqi=g9g-m1&aql=&gs_sm=e&gs_upl=5916l9958l0l10319l16l14l1l0l0l0l267l1925l0.6.4l10l0';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$htmls = curl_exec($ch);
curl_close($ch);
echo $htmls; <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn