Java版
1.方式一(推薦優(yōu)先使用該方式)文章來源:http://www.zghlxwxcb.cn/news/detail-585429.html
//driver配置
ChromeOptions chromeOptions=new ChromeOptions();
chromeOptions.setCapability("goog:loggingPrefs", Map.of("performance","ALL"));
ChromeDriver driver = new ChromeDriver(chromeOptions);
//將日志信息保存在list中
List<LogEntry> list = driver.manage().logs().get(LogType.PERFORMANCE).toJson();
2.方式二文章來源地址http://www.zghlxwxcb.cn/news/detail-585429.html
//driver配置
ChromeOptions chromeOptions=new ChromeOptions();
LoggingPreferences logs = new LoggingPreferences();
logs.enable(LogType.PERFORMANCE, Level.ALL);
chromeOptions.setCapability("goog:loggingPrefs", logs);
ChromeDriver driver = new ChromeDriver(chromeOptions);
//將日志信息保存在list中
List<LogEntry> list = driver.manage().logs().get(LogType.PERFORMANCE).toJson();
Python版
#driver配置
options = {'performance': 'ALL'}
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability('goog:loggingPrefs', options)
driver = webdriver.Chrome(options=chrome_options)
#將日志信息保存在list中
log = driver.get_log('performance')
到了這里,關于利用selenium獲取Chrome日志(Java版和Python版)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!