2017-04-04 107 views
-1

我試圖用我的腳本查詢谷歌,但我的要求是去Google.com頁面。如何從谷歌獲得JSON格式的結果?

我在找什麼是我可以請求谷歌的結果和出我的測試結果在JSON格式的HTML。這裏是我的嘗試:

<html> 
 
<body> 
 

 
<script type="text/javascript"> 
 
function google() 
 
{ 
 
var str=document.getElementById('googlebox').value; 
 
str="http://www.google.com/search?hl=en&source=hp&q=" + str + "&aq=f&oq=&aqi="; 
 
var replaced=str.replace(" ","+"); 
 
window.location.replace(replaced) 
 
} 
 
</script> 
 
<input type="text" value="Google" id="googlebox"/> 
 
<input type="button" value="Go" onclick="google()"/> 
 
</body> 
 
</html>

+0

你想實現搜索框功能在您的網頁,如果是那就試試這個「谷歌搜索」選項,簡單和容易。 https://developers.google.com/custom-search/docs/tutorial/implementingsearchbox –

+0

@BHUVANESHMOHANKUMAR,但我不打算使用谷歌API,因爲它有一些限制 –

回答

2

你不能。

對於任何給定的URL,服務器返回它返回的內容。

不能讓服務器以任意格式返回數據(或強制它使用CORS授予腳本讀取數據的權限)。

+0

有沒有辦法使用JavaScript刮?只有前10名的結果? –