Код: Выделить всё
def BingSearch(query):
import json
import os
from pprint import pprint
import requests
os.environ['Removed'] = 'https://api.bing.microsoft.com/'
subscription_key = os.environ['Removed']
endpoint = os.environ['Removed'] + "v7.0/search"
mkt = 'en-US'
params = { 'q': query, 'mkt': mkt }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }
try:
response = requests.get(endpoint, headers=headers, params=params)
response.raise_for_status()
"""
print("Headers: ")
print(response.headers)
print("JSON Response: ")
pprint(response.json())
"""
return response.json()['webPages']['value'] # return the 'value' list directly
except Exception as ex:
print(ex) # print the exception
time.sleep(0.25)
return [] # return an empty list when there's an exception
def print_urls(webPages):
#Cogni_Nexa_2.1.0.clear_screen()
site_Urls_New = []
if webPages: # check if webPages is not empty
for entry in webPages:
site_Urls_New.append(entry['url'])
else:
print("No web pages found.")
return site_Urls_New
def results_All_Querries(querry):
print (querry)
site_urls = []
for q in querry:
webSites = BingSearch(q)
urls = print_urls(webSites)
if urls: # if urls is not None
site_urls.extend(urls) # add the urls to site_urls
#clear_screen()
url_filtered = [url for url in site_urls if url.startswith("https://") or ("HTTPS") or ("http") or ("HTTP") or ("www") or ("WWW")]
clear_screen()
for url in url_filtered:
if url.startswith("https://") or ("http") or ("HTTPS") or ("HTTP") or ("www") or ("WWW"):
print(url+"\n")
else:
print ("\n")
return
Я закомментировал чистый экран и обнаружил, что он также показывает правильные сайты. но также кажется, что он делает что-то не по порядку. Я вставил результаты:
вот текстовый файл с ним: https://cdn.shopify.com/s/files/1/0692/ ... exa_output .txt?v=1719605414
Я разделил его на 3 изображения, которые вам нужно увеличить, чтобы прочитать.
изображение 1: https://cdn.shopify.com/ s/files/1/0692/7771/2667/files/tolong.jpg?v=1719605453
изображение 2:
https://cdn.shopify.com/s /files/1/0692/7771/2667/files/tolong2.jpg?v=1719605457
изображение 3:
https://cdn.shopify.com/s/ files/1/0692/7771/2667/files/tolong3.jpg?v=1719605424
они размещены на сайте моей компании. URL-адресов было слишком много, и текст слишком длинный, чтобы поместиться здесь.
Подробнее здесь: https://stackoverflow.com/questions/786 ... wser-cache