Skip to content

Instantly share code, notes, and snippets.

@truekonrads
Created November 14, 2012 21:53
Show Gist options
  • Save truekonrads/4075093 to your computer and use it in GitHub Desktop.
Save truekonrads/4075093 to your computer and use it in GitHub Desktop.
Bare bones Bing API
proxy_handler = ProxyHandler()
opener = build_opener(proxy_handler)
MAX_REQS=50
ENDPOINT="https://api.datamarket.azure.com/Bing/Search/Web?"
KEY='XAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
class Bing(object):
def __init__(self,key):
self.key=key
def query(self,query,maxreq=MAX_REQS,skip=0):
url=ENDPOINT+urlencode({
'$format':'json',
'Query':"'%s'" % query,
'$top': maxreq,
'$skip': skip
})
basic_auth="%s:%s" % (KEY,KEY)
request=Request(url,None,{'Authorization':"Basic " + basic_auth.encode('base64').replace("\n","")})
# print ">>URL: %s" % pprint(request.get_full_url())
# pprint(request.header_items())
result=opener.open(request)
return json.loads(result.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment