def search_res( q, subscription_key="3d12a190762442a79e1099a8f8ab1a3f", endpoint="https://chatbot-prototype-dev.cognitiveservices.azure.com"): client = WebSearchClient( endpoint=endpoint, credentials=CognitiveServicesCredentials(subscription_key)) web_data = client.web.search(query=q) res_pages = web_data.web_pages.value return res_pages
def websearch(search_term): subscription_key = "8357f85f67e347139e320820290c4bd0" # Instantiate the client and replace with your endpoint. client = WebSearchClient( endpoint="https://api.cognitive.microsoft.com", credentials=CognitiveServicesCredentials(subscription_key)) # Make a request. Replace Yosemite if you'd like. web_data = client.web.search(query=search_term) if hasattr(web_data.web_pages, 'value'): print("\r\nWebpage Results#{}".format(len(web_data.web_pages.value))) first_web_page = web_data.web_pages.value[0] print("First web page name: {} ".format(first_web_page.name)) print("First web page URL: {} ".format(first_web_page.url)) return first_web_page.url else: print("Didn't find any web pages...") return "N/A"
help="Environment variable with Bing Service Subscription Key. (AZURE_KEY)" ) parser.add_argument( '-e', dest='endpoint', default="https://seeds-search.cognitiveservices.azure.com/", help= "URL to your Azure Cognitive Service. (https://seeds-search.cognitiveservices.azure.com/)" ) args = parser.parse_args() subscription_key = os.environ[args.subscription_key_env_name] client = WebSearchClient( endpoint=args.endpoint, credentials=CognitiveServicesCredentials(subscription_key)) with open(args.queries_list_file, mode='r') as input_file: for line in input_file: query = line.rstrip() print("Querying for: {}".format(query)) try: web_data = client.web.search(query=query, count=args.results_number) if web_data.web_pages.value: print("Webpage Results #{}".format( len(web_data.web_pages.value))) with open(args.results_file, mode='a') as output_file:
endpoint = "https://azuretext1.cognitiveservices.azure.com/" from azure.ai.textanalytics import TextAnalyticsClient from azure.core.credentials import AzureKeyCredential from azure.cognitiveservices.search.entitysearch import EntitySearchClient from azure.cognitiveservices.search.entitysearch.models import Place, ErrorResponseException from msrest.authentication import CognitiveServicesCredentials from azure.cognitiveservices.search.websearch import WebSearchClient import docx2txt #setup for entity search subscription_key = "d8c84aab3fdb4dbcaa7b702f37fe4578" endpoint_search = "https://bingysearch.cognitiveservices.azure.com" client_bing = WebSearchClient(endpoint="https://bingysearch.cognitiveservices.azure.com",credentials=CognitiveServicesCredentials(subscription_key)) my_text = docx2txt.process("050B.docx") def authenticate_client(): ta_credential = AzureKeyCredential(key) text_analytics_client = TextAnalyticsClient( endpoint=endpoint, credential=ta_credential) return text_analytics_client client = authenticate_client() def sentiment_analysis_example(client): document = [my_text] response = client.analyze_sentiment(documents=document)[0]
print(">>>>> Searched for Query: \"Lady Gaga\"") if web_data.web_pages.value: print("Webpage Results: {}".format(len(web_data.web_pages.value))) for i in range(3): print("Name: {} ".format(web_data.web_pages.value[i].name)) print("URL: {} ".format(web_data.web_pages.value[i].url)) else: print("Didn't see any Web data..") if __name__ == "__main__": # Add your Bing Search V7 subscription key to your environment variables. SUBSCRIPTION_KEY = os.environ['BING_SEARCH_V7_SUBSCRIPTION_KEY'] ENDPOINT = os.environ['BING_SEARCH_V7_ENDPOINT'] # Initialize a client client = WebSearchClient(endpoint=ENDPOINT, credentials=CognitiveServicesCredentials(SUBSCRIPTION_KEY)) # Perform a search for different types: web pages, images, news, videos search_different_types(client) # Uses count and offset to start or end the certain on certain pages of the results search_with_count_and_offset(client) # Adds a response filter topic ("news") to the web page search search_with_response_filter(client) # Answer count restricts the types in the response (since the results contain many types). # Promote will focus on a search with ths promoted type, for example if you promote "videos". # Safe search sets the results to the level you want to restrict them (for inappropriate or adult content). search_with_answer_count_promote_and_safe_search(client)
from azure.cognitiveservices.search.websearch.models import SafeSearch from flask import Flask, request, render_template, jsonify from dotenv import load_dotenv load_dotenv() from markupsafe import escape printable = set(string.printable) # Load the values from environmental variables # The magic of dotenv COGSVCS_KEY = os.getenv('COGSVCS_KEY') COGSVCS_CLIENTURL = os.getenv('COGSVCS_CLIENTURL') ta_credential = CognitiveServicesCredentials(COGSVCS_KEY) search_client = WebSearchClient(endpoint=COGSVCS_CLIENTURL, credentials=ta_credential) app = Flask(__name__) file_to_read = json.load(open('holovid.json', encoding='utf8')) insights = file_to_read['summarizedInsights'] video = file_to_read['videos'] # @app.route('/getkeywords', methods=['GET']) def getkeywords(max_keywords=5, max_results=5): keywords = {} for ind, insight in enumerate(insights['keywords']): if ind >= max_keywords:
python -m pip install azure-cognitiveservices-search-websearch ''' # URL image, used as a reference only # To detect the faces and find the celebrity in this photo, use the Computer Vision service (optional). query_image_url = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/faces.jpg" # The name of the celebrity you want to search for on the web. celebrity_name = 'Bern Collaco' subscription_key = 'PASTE_YOUR_BING_SEARCH_SUBSCRIPTION_KEY_HERE' endpoint = 'PASTE_YOUR_BING_SEARCH_ENDPOINT_HERE' ''' Authenticate a client. ''' web_search_client = WebSearchClient( endpoint + 'bing/v7.0', CognitiveServicesCredentials(subscription_key)) ''' Bing Web Search Using the name of a celebrity, search for other images of them and return the source URL and image. This example uses the API calls: search() ''' print() print("===== Bing Web Search =====") print("Searching the web for:", celebrity_name) print() web_data = web_search_client.web.search( query=celebrity_name, # query search term response_filter=['Images'], # return only images safe_search='Strict', # filter the search to omit adult or racy content
def result_types_lookup(subscription_key): """WebSearchResultTypesLookup. This will look up a single query (Xbox) and print out name and url for first web, image, news and videos results. """ client = WebSearchClient(ENDPOINT, CognitiveServicesCredentials(subscription_key)) try: web_data = client.web.search(query="xbox") print("Searched for Query# \" Xbox \"") # WebPages if web_data.web_pages.value: print("Webpage Results#{}".format(len(web_data.web_pages.value))) first_web_page = web_data.web_pages.value[0] print("First web page name: {} ".format(first_web_page.name)) print("First web page URL: {} ".format(first_web_page.url)) else: print("Didn't see any Web data..") # Images if web_data.images.value: print("Image Results#{}".format(len(web_data.images.value))) first_image = web_data.images.value[0] print("First Image name: {} ".format(first_image.name)) print("First Image URL: {} ".format(first_image.url)) else: print("Didn't see any Image..") # News if web_data.news.value: print("News Results#{}".format(len(web_data.news.value))) first_news = web_data.news.value[0] print("First News name: {} ".format(first_news.name)) print("First News URL: {} ".format(first_news.url)) else: print("Didn't see any News..") # Videos if web_data.videos.value: print("Videos Results#{}".format(len(web_data.videos.value))) first_video = web_data.videos.value[0] print("First Videos name: {} ".format(first_video.name)) print("First Videos URL: {} ".format(first_video.url)) else: print("Didn't see any Videos..") except Exception as err: print("Encountered exception. {}".format(err))
def __init__(self, *args): super().__init__(*args) self.client = WebSearchClient(endpoint=os.getenv('SEARCH_ENDPOINT'), credentials=CognitiveServicesCredentials(os.getenv('SEARCH_API')))
from azure.cognitiveservices.search.websearch import WebSearchClient from azure.cognitiveservices.search.websearch.models import SafeSearch from msrest.authentication import CognitiveServicesCredentials from subkey import sub_key import re subscription_key = sub_key() client = WebSearchClient("https://westeurope.api.cognitive.microsoft.com/", CognitiveServicesCredentials(subscription_key)) #returnt eine liste von top 5 newswebsiten die dieses keyword in letzter zeit verwendet haben def az_get_links_for_key(key, menge): web_data = client.web.search(query=key, count=menge, market="de-DE", set_lang="DE") sites = [] if hasattr(web_data.web_pages, 'value'): for news in web_data.web_pages.value: sites.append(lc_clean_url(news.url)) return sites #räumt die url auf auf format URL.TLD def lc_clean_url(url): try: t = re.search(r'\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{1,3}', url).group(0) t = t.replace("//", "")