Sunday, 11 August 2013

Replace variable in url for bing search

Replace variable in url for bing search

I have a code to get urls from bing search.
import requests
URL =
"https://mykey:mykey@api.datamarket.azure.com/Bing/Search/Web?$format=json&Query='query'"
API_KEY = 'mykey'
query = "JohnDalton"
def request(query, **params):
query = ('%27'+query+ '%27')
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
print r.content
return r.json()['d']['results']
r = request("JohnDalton")
print r[0]['Url']
The script only gets urls related to "query" which i have put in the url,
Even though i have tried replacing the value with the vairable query in
the line;
r = requests.get(URL % {'query': query}, auth=('', API_KEY))
Why is it not replacing the values?

No comments:

Post a Comment