在python中如何收集具有级别警告的日志?

在python中如何收集具有级别警告的日志?,python,selenium,logging,warnings,Python,Selenium,Logging,Warnings,我有一个代码,据了解,它应该是收集3个日志文件与日志级别警告,但其收集25个文件与级别信息。我怎么可能堆叠在哪里 mail_url = 'https://mail.yandex.ru' caps = DesiredCapabilities.CHROME caps['loggingPrefs'] = {'performance': 'WARNING'} driver = webdriver.Chrome(desired_capabilities=caps) def get_log():

我有一个代码,据了解,它应该是收集3个日志文件与日志级别警告,但其收集25个文件与级别信息。我怎么可能堆叠在哪里

mail_url = 'https://mail.yandex.ru'
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'WARNING'}
driver = webdriver.Chrome(desired_capabilities=caps)

def get_log():
    for entry in driver.get_log('performance'):
        date_stamp = str(datetime.datetime.now()).split('.')[0]
        date_stamp = date_stamp.replace(" ", "_").replace(":", "_").replace("-", "_")
        fileVar = open("log_" + date_stamp + ".txt", "w")
        fileVar.write(str(entry))
        fileVar.close()

def take_screenshot():
    date_stamp = str(datetime.datetime.now()).split('.')[0]
    date_stamp = date_stamp.replace(" ", "_").replace(":", "_").replace("-", "_")
    driver.save_screenshot(date_stamp + ".png")

driver.set_window_size(360, 740) #open ya.ru in 360x740
driver.get('https://ya.ru')
time.sleep (5)
get_log()

driver.set_window_size(1920, 1080) #open ya.ru in 1920x1080
driver.get('https://ya.ru')
time.sleep (5)
get_log()

target = driver.find_element_by_xpath('//a[@href="' + mail_url + '"]') 
builder = ActionChains(driver)
builder.move_to_element(target).perform()
get_log()
driver.set_window_size(800, 600)
loggingPrefs键应该是browser,而不是performance


是的,很有效,谢谢。但现在我只有2个日志文件:看起来我遗漏了其他东西。
caps['loggingPrefs'] = {'browser': 'WARNING'}
driver = webdriver.Chrome(desired_capabilities=caps)

for entry in driver.get_log('browser'):
    # ...