0
$query = "Poultry meat is a major source of animal protein considering";
function fetch_google($query) {
$cleanQuery = str_replace(" ","+",$query);
$url = 'http://www.google.com/search?q='.urlencode($cleanQuery);
$data=file_get_contents($url);
$json = json_decode($data, true);
for($x=0;$x<count($json->responseData->results);$x++){
echo "<b>Result ".($x+1)."</b>";
echo "<br>URL: ";
echo $json->responseData->results[$x]->url;
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>";
}
}
fetch_google($query);
我試圖獲得搜索結果,但在返回json_decode給予空值.. 試圖尋找答案,但失敗。谷歌搜索,json_decode給出null
var_dump($url);
給出結果..但不是$ JSON
是否有任何其他方式來獲取不帶API的特定數據? –
如果您從http://www.google.com/search?q=解析HTML結果,則不確定它們的格式是否相同。也許明天谷歌決定改變他們顯示結果的方式。最好的選擇是使用API,這是更容易的。 –
好吧..請給出一個示例代碼..不能理解谷歌文檔.. –