Skip to content

Commit 43ddef9

Browse files
author
Aaron Hill
committed
updating python code sample
1 parent 6a25b8f commit 43ddef9

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

samples/search/custom_search_samples.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1+
# <imports>
2+
import os
13
from azure.cognitiveservices.search.customsearch import CustomSearchClient
24
from msrest.authentication import CognitiveServicesCredentials
5+
# </imports>
36

7+
# <vars>
48
SUBSCRIPTION_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

3239
if __name__ == "__main__":
3340
import sys

0 commit comments

Comments
 (0)