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 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥15 stm32 串口通讯过程中的问题
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问