Last active
June 21, 2016 11:34
-
-
Save alexmill/cd6ec9ebf1e5ee5fd314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3.3 | |
# Gist available at: https://gist.github.com/alexmill/cd6ec9ebf1e5ee5fd314 | |
# From article hosted at: http://alex.miller.im/posts/bing-azure-api-authentication-python-requests/ | |
from urllib.parse import quote_plus | |
import json | |
import requests | |
def bing_search(query): | |
# Your base API URL | |
url = "https://api.datamarket.azure.com/Bing/Search/v1/Web" | |
# Query parameters. Don't try using urlencode here. | |
# Don't ask why, but Bing needs the "$" in front of its parameters. | |
# The '$top' parameter limits the number of search results. | |
url += "?$format=json&$top=10&Query=%27{}%27".format(quote_plus(query)) | |
# You can get your primary account key at https://datamarket.azure.com/account | |
r = requests.get(url, auth=("","YOUR_AZURE_API_PRIMARY_ACCOUNT_KEY")) | |
resp = json.loads(r.text) | |
return(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great. Thanks!