简体   繁体   中英

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.

What I am looking for is how I can request google for result and out the result on my test html in json format. 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.

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

You should look into google's custom search API. It has an option to return data in JSON format.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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