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);