我想cURL google搜索结果在php [英] I want to cURL google search result in php

查看:159
本文介绍了我想cURL google搜索结果在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过下列代码:

$url = 'http://www.google.co.uk/#q='.$query.'&hl=en&prmd=imvns&source=lnt&tbs=ctr:countryUK%7CcountryGB&cr=countryUK%7CcountryGB&sa=X&psj=1&ei=m65DT_yUAcnG0QX46_yPDw&ved=0CEEQpwUoAQ&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=2e9b4f7fb1e75d0d&biw=1440&bih=799';

$ch = curl_init();

curl_setopt($ch, CURLOPT_PROXY, '192.168.0.1:1501');
curl_setopt($ch, CURLOPT_REFERER, 'www.google.com');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);

$contents = curl_exec($ch);

curl_close($ch);

echo $contents;

但它显示google首页而不是google搜索结果页。
帮助我解决这个问题。

But it shows google homepage instead of google search result page. Help me to resolve this problem.

推荐答案

我成功地绕过了google尝试防止curl

I was successfully able to bypass google's attempt to prevent curl search by the following:

$useragent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.14912/870; U; id) Presto/2.4.15";
$ch = curl_init ("");
curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q=".$query);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
echo $output = curl_exec ($ch);
curl_close($ch);

请注意,我使用的用户代理是一个老歌剧迷你浏览器。

Note the user agent I used is an old opera mini browser. this way google displays an html content that you can parse.

这是针对Google服务条款的,请不要滥用;)

THIS IS AGAINST GOOGLE TOS, please do not abuse ;)

use $ query = urlencode($ query)

这篇关于我想cURL google搜索结果在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆