Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexmill/cd6ec9ebf1e5ee5fd314 to your computer and use it in GitHub Desktop.
Save alexmill/cd6ec9ebf1e5ee5fd314 to your computer and use it in GitHub Desktop.
#!/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)
@tommct
Copy link

tommct commented Feb 24, 2016

This is great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment