[英]different number of results using google search api
I use google search API to extract the 80th first results. 我使用Google搜索API提取了第80个结果。 My problem is that each time I run the program, it gives me a different number of results (URLs).
我的问题是,每次运行程序时,它都会给我带来不同数量的结果(URL)。
Notice: Trying to get property of non-object on line 42
注意:尝试获取第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);
Look at this answer - https://stackoverflow.com/a/4353393/5214904 . 看看这个答案-https: //stackoverflow.com/a/4353393/5214904 。 In short: there is a limit without API key in 64 results
简而言之:64个结果中没有API密钥的限制
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. 已修改 :请参见https://developers.google.com/web-search/docs/#php-access。您需要在url中发送您的/客户端IP,在REFERER字段中发送您的站点。 You can do it with CURL.
您可以使用CURL做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.