簡體   English   中英

如何使用 python selenium 訪問 google chrome 開發人員工具上的安全面板?

[英]How to access Security panel on google chrome developer tools with python selenium?

以下 python 代碼可以獲取控制台日志,但是如何訪問 Chrome devTools上的Security選項卡? 例如,我想記錄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()

好的,我的解決方案如下:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM