Skip to content

Commit ae46875

Browse files
authored
Updated structure, added pretty print
1 parent 7f527f8 commit ae46875

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
#Copyright (c) Microsoft Corporation. All rights reserved.
2-
#Licensed under the MIT License.
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
33

44
# You may need the below as well
5-
#pip install pipenv
6-
#pipenv install requests
5+
# pip install pipenv
6+
# pipenv install requests
77
# <importsAndVars>
88
import json
9-
import requests
109
import os
10+
from pprint import pprint
11+
import requests
1112

12-
# Add your Bing Custom Search subscription key to your environment variables.
13-
# Your endpoint will have the form: https://<your-custom-subdomain>.cognitiveservices.azure.com/bingcustomsearch/v7.0
13+
'''
14+
This sample uses the Bing Custom Search API to search for a query topic and get back user-controlled web page results.
15+
Bing Custom Search API: https://docs.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-custom-search-api-v7-reference
16+
'''
17+
18+
# Add your Bing Custom Search subscription key and endpoint to your environment variables.
19+
# Your endpoint will have the form: https://<your-custom-subdomain>.cognitiveservices.azure.com
1420
subscriptionKey = os.environ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY']
1521
endpoint = os.environ['BING_CUSTOM_SEARCH_ENDPOINT']
16-
customConfigId = "your-custom-config-id" #you can also use "1"
22+
customConfigId = os.environ["BING_CUSTOM_CONFIG"] # you can also use "1"
1723
searchTerm = "microsoft"
1824
# </importsAndVars>
1925
# <url>
2026
# Add your Bing Custom Search endpoint to your environment variables.
21-
url = endpoint + "/search?q=" + searchTerm + "&customconfig=" + customConfigId
27+
url = endpoint + "/bingcustomsearch/v7.0/search?q=" + searchTerm + "&customconfig=" + customConfigId
2228
# </url>
2329
# <request>
2430
r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey})
25-
print(r.text)
31+
pprint(json.loads(r.text))
2632
# </request>

0 commit comments

Comments
 (0)