我多次尝试获取性能日志,但我不知道为什么我的代码不起作用,它总是在 Performance_logs = driver.get_log("performance") 处中断
from selenium import webdriver
import time
import json
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import TimeoutException
options = webdriver.ChromeOptions()
options.add_argument("goog:loggingPrefs={\"performance\": \"ALL\"}")
options.add_argument("--auto-open-devtools-for-tabs")
options.add_argument("--enable-logging")
options.add_argument("--log-level=ALL")
options.add_argument("--verbose")
# options.add_argument("--headless")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)
dev_tools = driver.execute_cdp_cmd("Performance.enable", {})
driver.get("https://gist.github.com/")
performance_logs = driver.get_log("performance")
print(driver.log_types)
time.sleep(10)
driver.quit()
:(((((((((((((((((((((
))而不是
performance_logs
你可以尝试下面的代码并检查
for performance_logs in driver.get_log('performance'):
print(performance_logs)