问题
i read your post on
simple php script to retrieve google keyword search completion
and i was wondering how would you go 'echo' the next page? here's my script..
$search = 'query';
$x = json_decode( file_get_contents( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' . urlencode( $search ) ) );
echo $x->responseData->results[0]->url;
i was able to 'echo' out the url, i am stucked in going to the next page and 'echo' out the next url's
thanks sir
回答1:
You change the index:
echo $x->responseData->results[1]->url;
To loop through all:
foreach ($x->responseData->results as $r) {
echo $r->url, "\n";
}
You can inspect the complete result with var_dump($x);
.
To retrieve another page of results, you can use the start
parameter, e.g.:
$x = json_decode(
file_get_contents(
'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=4&q='
. urlencode( $search )));
You can request 8 results instead of 4 with rsz=large
.
回答2:
For anyone else looking to interface with Google and stumbled on this solution, the code above now returns this response: object(stdClass)#1 (3) { ["responseData"]=> NULL ["responseDetails"]=> string(143) "The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)" ["responseStatus"]=> int(403) }
Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/) I hope this saves someone some time!
来源:https://stackoverflow.com/questions/3436525/retrieving-google-search-results