File tree Expand file tree Collapse file tree 1 file changed +20
-13
lines changed
Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change 1+ # <imports>
2+ import os
13from azure .cognitiveservices .search .customsearch import CustomSearchClient
24from msrest .authentication import CognitiveServicesCredentials
5+ # </imports>
36
7+ # <vars>
48SUBSCRIPTION_KEY = os .environ ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY' ]
5-
6-
7- def custom_search_web_page_result_lookup (subscription_key ):
8- """CustomSearch.
9-
10- This will look up a single query (Xbox) and print out name and url for first web result.
11- """
12-
13- client = CustomSearchClient (CognitiveServicesCredentials (subscription_key ))
14-
9+ search_term = "xbox"
10+ custom_config = "your-custom-config-id" # You can also use "1"
11+ # </vars>
12+
13+ # <authentication>
14+ client = CustomSearchClient (CognitiveServicesCredentials (SUBSCRIPTION_KEY ))
15+ # </authentication>
16+
17+ """CustomSearch.
18+ This will look up a single query and print out name and url for first web result.
19+ """
20+ # <request>
21+ def custom_search_web_page_result_lookup ():
1522 try :
16- web_data = client .custom_instance .search (query = "xbox" , custom_config = 1 )
17- print ("Searched for Query 'xbox'" )
23+ web_data = client .custom_instance .search (query = search_term , custom_config = 1 )
24+ print ("Searched for Query: " + search_term )
1825
1926 if web_data .web_pages .value :
2027 first_web_result = web_data .web_pages .value [0 ]
@@ -27,7 +34,7 @@ def custom_search_web_page_result_lookup(subscription_key):
2734
2835 except Exception as err :
2936 print ("Encountered exception. {}" .format (err ))
30-
37+ # <request>
3138
3239if __name__ == "__main__" :
3340 import sys
You can’t perform that action at this time.
0 commit comments