先确保彻底关闭浏览器所有进程,找到自己的浏览器位置,再用如下命令打开浏览器
"C:\Users\28353\AppData\Local\Google\Chrome\Application\chrome.exe" --remote-debugging-port=8888 --disable-gpu
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import json
from selenium import webdriver
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = {'performance': 'ALL'}
d['goog:loggingPrefs'] = {'performance': 'ALL'}
options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:8888"
driver = webdriver.Chrome(desired_capabilities=d, options=options)
driver.get('https://www.baidu.com')
for log in driver.get_log('performance'):
x = json.loads(log['message'])['message']
print(x)
结果如图: