File tree Expand file tree Collapse file tree 1 file changed +13
-20
lines changed
Expand file tree Collapse file tree 1 file changed +13
-20
lines changed Original file line number Diff line number Diff line change 1- # <imports>
2- import os
31from azure .cognitiveservices .search .customsearch import CustomSearchClient
42from msrest .authentication import CognitiveServicesCredentials
5- # </imports>
63
7- # <vars>
84SUBSCRIPTION_KEY = os .environ ['BING_CUSTOM_SEARCH_SUBSCRIPTION_KEY' ]
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 ():
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+
2215 try :
23- web_data = client .custom_instance .search (query = search_term , custom_config = 1 )
24- print ("Searched for Query: " + search_term )
16+ web_data = client .custom_instance .search (query = "xbox" , custom_config = 1 )
17+ print ("Searched for Query 'xbox'" )
2518
2619 if web_data .web_pages .value :
2720 first_web_result = web_data .web_pages .value [0 ]
@@ -34,7 +27,7 @@ def custom_search_web_page_result_lookup():
3427
3528 except Exception as err :
3629 print ("Encountered exception. {}" .format (err ))
37- # <request>
30+
3831
3932if __name__ == "__main__" :
4033 import sys
You can’t perform that action at this time.
0 commit comments