如何从PHP的api获取所有谷歌搜索结果?

时间:2010-12-04 08:05:52

标签: php

我正在使用此代码:

function doGoogleSearch($searchTerm)
  {
   //$cx="002000009380213215808:hf9v-g9oyho";        
    $endpoint = 'web';
    $key= 'XXX';
    $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint;

    $args['q'] = $searchTerm;
    $args['v'] = '1.0';

    $url .= '?'.http_build_query($args, '', '&');

    $ch = curl_init()or die("Cannot init");
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
    $body = curl_exec($ch)or die("cannot execute");
    curl_close($ch);
    //decode and return the response
    return json_decode($body,1);
  }

通过使用这个我只得到了它的第1个结果。是否有任何方法可以获得谷歌的整个搜索结果?

2 个答案:

答案 0 :(得分:0)

正如指出in the Google Web Search API Class Reference,您可以使用rsz = 8一次获得8个结果,start = xxx更改结果的“页面”(即获取下一组8)

一次无法获得超过8个结果,并且返回的最大结果数为64(请参阅解释here,再次in the Class Reference)。

此外,不推荐使用Web Search API,您应该改为使用Custom Search API

答案 1 :(得分:0)

http://pear.php.net/package/Services_Google

但谷歌仅访问您进行有限搜索

相关问题