Reputation: 21
I want to execute a google query with requests module in python. Here is my script:
import requests
searchfor = 'test'
payload = {'q': searchfor, 'key': API_KEY, 'cx': SEARCH_ENGINE_ID}
link = 'https://www.googleapis.com/customesearch/v1'
r = requests.get(link, paramas=payload)
print r.content
and then run the script as: ./googler.py > out
and the out is in json format.
How can I get the responce in http format?
Upvotes: 0
Views: 67
Reputation: 579
The google api only supports atom/Json.
So you have to parse the JSON to HTML. You maybe want to check json package.
append something like this to your file:
import json
items = json.loads(r)['items']
print "<html><body>"
for item in items:
print "<a href=" +item['url'] + ">" + item['title'] + "</a>"
print "</body></html>"
Upvotes: 1