Skip to content

Commit

Permalink
Updated structure, added pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
wiazur authored Jan 24, 2020
1 parent 7f527f8 commit ae46875
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions python/Search/BingCustomSearchv7.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
#Copyright (c) Microsoft Corporation. All rights reserved.
#Licensed under the MIT License.
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# You may need the below as well
#pip install pipenv
#pipenv install requests
# pip install pipenv
# pipenv install requests
# <importsAndVars>
import json
import requests
import os
from pprint import pprint
import requests

# Add your Bing Custom Search subscription key to your environment variables.
# Your endpoint will have the form: https://<your-custom-subdomain>.cognitiveservices.azure.com/bingcustomsearch/v7.0
'''
This sample uses the Bing Custom Search API to search for a query topic and get back user-controlled web page results.
Bing Custom Search API: https://docs.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-custom-search-api-v7-reference
'''

# Add your Bing Custom Search subscription key and endpoint to your environment variables.
# Your endpoint will have the form: https://<your-custom-subdomain>.cognitiveservices.azure.com
subscriptionKey = os.environ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY']
endpoint = os.environ['BING_CUSTOM_SEARCH_ENDPOINT']
customConfigId = "your-custom-config-id" #you can also use "1"
customConfigId = os.environ["BING_CUSTOM_CONFIG"] # you can also use "1"
searchTerm = "microsoft"
# </importsAndVars>
# <url>
# Add your Bing Custom Search endpoint to your environment variables.
url = endpoint + "/search?q=" + searchTerm + "&customconfig=" + customConfigId
url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId
# </url>
# <request>
r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey})
print(r.text)
pprint(json.loads(r.text))
# </request>

0 comments on commit ae46875

Please sign in to comment.