[英]How to access Security panel on google chrome developer tools with python selenium?
The following python code can get console log, but how can I access Security
tab on Chrome devTools
?以下 python 代码可以获取控制台日志,但是如何访问 Chrome
devTools
上的Security
选项卡? Eg I want to log about This page is secure or not (HTTPS) and the TLS certificate status
.例如,我想记录
This page is secure or not (HTTPS) and the TLS certificate status
。
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
yoururl = "test_url"
caps = DesiredCapabilities.CHROME
caps['goog:loggingPrefs'] = {'browser': 'ALL'}
# driver = webdriver.Chrome(desired_capabilities=caps)
driver = webdriver.Chrome('path_of_chromedriver', desired_capabilities=caps)
driver.get(yoururl)
time.sleep(5) # wait for all the data to arrive.
for log in driver.get_log('browser'):
print(log)
driver.close()
Ok, my solution is as follows:好的,我的解决方案如下:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import json
caps = DesiredCapabilities.CHROME.copy()
caps['goog:loggingPrefs'] = {
'performance': 'ALL',
}
caps['goog:perfLoggingPrefs'] = {
'enableNetwork': True
}
option = webdriver.ChromeOptions()
option.add_argument('--ignore-certificate-errors')
# option.add_experimental_option('w3c', False)
driver = webdriver.Chrome('chromedriver.exe', options=option, desired_capabilities=caps)
yoururl = "https://www.google.com.tw/"
driver.get(yoururl)
time.sleep(5)
for log_data in driver.get_log('performance'):
log_json = json.loads(log_data['message'])
log = log_json['message']
if log['method'] == 'Network.responseReceived' and log['params']['response']['url'] == yoururl:
print(f"securityState={log['params']['response']['securityState']}")
print(f"securityDetails={log['params']['response']['securityDetails']}")
driver.quit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.