Python google query with requests module, get responce in http format
Question: 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?


Answer: The google api only supports [atom/Json](https://developers.google.com/custom-
search/json-api/v1/overview).

So you have to parse the JSON to HTML. You maybe want to check [json
package](https://docs.python.org/2/library/json.html).

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

