简体   繁体   English

如何从Google获取JSON格式的结果?

[英]How to get the result in JSON format from google?

I have tried to query google using my script but my request is going to Google.com page. 我尝试使用脚本查询Google,但我的请求将转到Google.com页面。

What I am looking for is how I can request google for result and out the result on my test html in json format. 我正在寻找的是如何向Google请求结果并以json格式在我的测试html上输出结果。 Here is what I tried: 这是我尝试过的:

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

You can't. 你不能

For any given a URL, a server returns what it returns. 对于任何给定的URL,服务器将返回其返回的内容。

You can't make a server return data in an arbitrary format (or force it to use CORS to grant permission to your script to read that data). 您不能使服务器以任意格式返回数据(或强制服务器使用CORS授予脚本读取该数据的权限)。

You should look into google's custom search API. 您应该研究Google的自定义搜索API。 It has an option to return data in JSON format. 它具有返回JSON格式的数据的选项。

https://developers.google.com/custom-search/json-api/v1/using_rest https://developers.google.com/custom-search/json-api/v1/using_rest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM