【问题标题】:How to turn off command line logging in Selenium using Chrome in Python如何在 Python 中使用 Chrome 关闭 Selenium 中的命令行日志记录
【发布时间】:2018-05-12 13:18:42
【问题描述】:

我正在尝试使用 Selenium 运行 Python 脚本,虽然一切运行良好,但我个人 print() 到控制台的行却隐藏在大量 Selenium/Chromedriver 输出之间,如下所示:

1128/150256.806:INFO:CONSOLE(0)] "The SSL certificate used to load resources from [some-link.com] will be distrusted in the future. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.", source: [current-page.com] (0)

我检查了这些链接是什么,它们只是我正在查看的页面上的广告,所以它完全没用。此外,由于每次页面加载/重新加载时都会随机生成广告,因此链接不同,因此输出永无止境。这非常烦人,并且很难看到我的程序中实际发生了什么。有没有办法通过一些 Selenium 选项或其他东西来关闭它?

奇怪的是,使用 PyDev 在 Eclipse Oxygen 中运行程序根本不会显示 Selenium 的任何输出,除非我使用命令行运行它。

编辑:按照提到的可能重复项中的说明进行操作没有帮助。我尝试将日志记录级别设置为最高级别,即 CRITICAL,但上面提到的输出仍然通过并淹没了控制台。

【问题讨论】:

标签: python windows selenium command-line


【解决方案1】:

解决此问题的最佳方法是将 --log-level 选项添加到您的驱动程序。看起来像这样:

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--log-level=3")
driver = webdriver.Chrome(chrome_options=chrome_options)

【讨论】:

  • 由于某种原因,这对我不起作用。仍然看到:[WDM] - 当前的 google-chrome 版本是 85.0.4183 Selenium 补丁。安全导入 Chrome / ChromeOptions
【解决方案2】:

通过 webdriver_manager 包使用 ChromeDriverManager 的人可以使用以下命令禁用 [WDM] 日志消息:

import os
os.environ["WDM_LOG_LEVEL"] = str(logging.WARNING)

【讨论】:

    猜你喜欢
    • 2010-09-24
    • 2016-01-17
    • 1970-01-01
    • 2019-10-26
    • 2020-10-18
    • 2020-09-18
    • 1970-01-01
    • 2021-11-23
    • 2019-08-11
    相关资源
    最近更新 更多