简体   繁体   English

如何使用 python selenium 访问 google chrome 开发人员工具上的安全面板?

[英]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.

相关问题 我可以使用 python 访问谷歌浏览器开发者工具的网络选项卡吗? - can I access to network tab of google chrome developer tools with python? 如何使用 python 在 chrome 开发人员工具中访问网络选项卡 - How to access network tab in chrome developer tools using python 如何使用 python selenium webdriver 在 Chrome 开发人员工具控制台中进行 fetch 调用 - How to make a fetch call in Chrome developer tools console using python selenium webdriver Selenium 相当于使用 Google Chrome 开发者工具并在最外面的 HTML 元素上单击“复制 OuterHTML”? - What is the Selenium equivalent of using Google Chrome Developer Tools and clicking "Copy OuterHTML" on the outermost HTML element? 如何在 Python 中使用 Selenium 打开 chrome 开发者控制台? - How to open chrome developer console using Selenium in Python? 如何在 python 上使用 selenium 关闭 google chrome 弹出窗口? - How to close google chrome popups with selenium on python? 无法启用开发者模式 chrome selenium python - Cannt enable developer mode chrome selenium python 如何在python中将现有的Google Chrome配置文件与Selenium Chrome Webdriver一起使用? - How to use an existing google chrome profile with selenium chrome webdriver in python? Python selenium 获取“开发者工具”→网络→媒体日志 - Python selenium get "Developer Tools" →Network→Media logs Python 请求标头不起作用 - 检查 Chrome 开发者工具 -> 网络 - Python requests header not working - Checked Chrome developer tools -> Network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM