我使用谷歌搜索API来提取第80个第一个结果。 我的问题是,每次运行程序时,它都会给我不同数量的结果(URL)。
<?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);注意:尝试在第42行获取非对象的属性
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).
<?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);Notice: Trying to get property of non-object on line 42
最满意答案
看看这个答案 - 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.
更多推荐
发布评论