dongsheng4126335 2015-08-27 14:32
浏览 117
已采纳

使用谷歌搜索API的不同数量的结果

I use google search API to extract the 80th first results. My problem is that each time I run the program, it gives me a different number of results (URLs).

Notice: Trying to get property of non-object on line 42

    <?php

    $query='site:https://fr.wikipedia.org%20sport';
    $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&hl=fr&rsz=large&q=".$query;

    $body = file_get_contents($url);
    $json = json_decode($body);

    $inF = fopen("fnm.txt","a"); 
    for($x=0;$x<count($json->responseData->results);$x++){

    echo "<b>Result ".($x+1)."</b>";
    echo "<br>URL: ";
    echo $json->responseData->results[$x]->url;
    fputs($inF,$json->responseData->results[$x]->url); fwrite($inF, "
");
    echo "<br>VisibleURL: ";
    echo $json->responseData->results[$x]->visibleUrl;
    echo "<br>Title: ";
    echo $json->responseData->results[$x]->title;
    echo "<br>Content: ";
    echo $json->responseData->results[$x]->content;
    echo "<br><br>";
    }

    $j=0;
    for ($i= 0; $i <= 10; $i++) 
    {
     $j=$j+8;
     echo $j;
     $query = 'site:https://fr.wikipedia.org%20sport';
      $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&hl=fr&rsz=large&start=$j&q=".$query;

     $body = file_get_contents($url);
     $json = json_decode($body);

    for($x=0;$x<count($json->responseData->results);$x++){

    echo "<b>Result ".($x+1)."</b>";
    echo "<br>URL: ";
    echo $json->responseData->results[$x]->url;
    fputs($inF,$json->responseData->results[$x]->url); fwrite($inF, "
");
    echo "<br>VisibleURL: ";
    echo $json->responseData->results[$x]->visibleUrl;
    echo "<br>Title: ";
    echo $json->responseData->results[$x]->title;
    echo "<br>Content: ";
    echo $json->responseData->results[$x]->content;
    echo "<br><br>";
    }

}

fclose ($inF);
  • 写回答

1条回答 默认 最新

  • douboshan1466 2015-08-27 14:52
    关注

    Look at this answer - https://stackoverflow.com/a/4353393/5214904. In short: there is a limit without API key in 64 results

    Edited: See https://developers.google.com/web-search/docs/#php-access You need to send your/client IP in url and your site in REFERER field. You can do it with CURL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多