使用谷歌搜索API的不同数量的结果(different number of results using google search api)

编程入门 行业动态 更新时间:2024-10-24 22:18:46
使用谷歌搜索API的不同数量的结果(different number of results using google search api)

我使用谷歌搜索API来提取第80个第一个结果。 我的问题是,每次运行程序时,它都会给我不同数量的结果(URL)。

注意:尝试在第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, "\r\n"); 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, "\r\n"); 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);

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, "\r\n"); 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, "\r\n"); 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);

最满意答案

看看这个答案 - https://stackoverflow.com/a/4353393/5214904 。 简而言之:64个结果中没有API密钥的限制

已编辑 :请参阅https://developers.google.com/web-search/docs/#php-access您需要在网址和REFERER字段中发送您的/客户端IP。 你可以用CURL做到这一点。

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.

更多推荐

本文发布于:2023-07-04 16:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数量   number   API   results   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!