Python google query with requests module, get responce in http format
<p>I want to execute a google query with requests module in python. Here is my script:</p>

<pre><code>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
</code></pre>

<p>and then run the script as: ./googler.py > out</p>

<p>and the out is in json format.</p>

<p>How can I get the responce in http format?</p>

<p>The google api only supports <a href="https://developers.google.com/custom-search/json-api/v1/overview" rel="nofollow">atom/Json</a>. </p>

<p>So you have to parse the JSON to HTML.
You maybe want to check <a href="https://docs.python.org/2/library/json.html" rel="nofollow">json package</a>.</p>

<p>append something like this to your file:</p>

<pre><code>import json
items = json.loads(r)['items']
print "&lt;html&gt;&lt;body&gt;"
for item in items:
    print "&lt;a href=" +item['url'] + "&gt;" + item['title'] + "&lt;/a&gt;"
print "&lt;/body&gt;&lt;/html&gt;"
</code></pre>

python json http google-app-engine request