Created
June 15, 2013 23:05
-
-
Save gavinmh/5789928 to your computer and use it in GitHub Desktop.
Bing Search API Python example
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
| import urllib | |
| import json | |
| bing_account_key = '<YOURKEY>' | |
| search_base_url = \ | |
| 'https://user:%s@api.datamarket.azure.com/Bing/SearchWeb/Web?' \ | |
| % bing_account_key | |
| query = 'les paul' | |
| num_results = 40 | |
| bing_parameters = { | |
| "Query": "'%s'" % query, | |
| "Market": "'en-US'", | |
| "$top": num_results, | |
| "$format": "JSON" | |
| } | |
| queryString = urllib.urlencode(bing_parameters) | |
| url = search_base_url + queryString | |
| json_data = urllib.urlopen(url) | |
| results = json.load(json_data) | |
| print results | |
| print '\n' | |
| for i in results['d']['results']: | |
| print i['Description'], '\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment