|
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. |
3 | 3 |
|
4 | 4 | # You may need the below as well |
5 | | -#pip install pipenv |
6 | | -#pipenv install requests |
| 5 | +# pip install pipenv |
| 6 | +# pipenv install requests |
7 | 7 | # <importsAndVars> |
8 | 8 | import json |
9 | | -import requests |
10 | 9 | import os |
| 10 | +from pprint import pprint |
| 11 | +import requests |
11 | 12 |
|
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 |
14 | 20 | subscriptionKey = os.environ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY'] |
15 | 21 | 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" |
17 | 23 | searchTerm = "microsoft" |
18 | 24 | # </importsAndVars> |
19 | 25 | # <url> |
20 | 26 | # 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 |
22 | 28 | # </url> |
23 | 29 | # <request> |
24 | 30 | r = requests.get(url, headers={'Ocp-Apim-Subscription-Key': subscriptionKey}) |
25 | | -print(r.text) |
| 31 | +pprint(json.loads(r.text)) |
26 | 32 | # </request> |
0 commit comments