-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated structure, added pretty print
- Loading branch information
Showing
1 changed file
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
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> |