如何在Python中隐藏selenium的chromedriver的cmd.exe/console日志?

2024-04-19 11:08:11 发布

您现在位置:Python中文网/ 问答频道 /正文

如何隐藏cmd.exe/控制台在python中记录硒中的chromedriver?在

我试过了:

driver.service.stop()

完整代码:

^{pr2}$

但它没有关闭控制台日志/命令行.exe在

See the console log image


Tags: 代码命令行cmddriverservice记录exechromedriver
2条回答

您无法在Chrome驱动程序中完全隐藏它,但您可以抑制少数,并设置最低日志级别,如下所示:

from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('log-level=2')

其中日志级别为

^{pr2}$
  #Combine this two options: 

  from selenium.webdriver.chrome.options import Options
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

  options = Options()
  options.add_argument(' log-level=3')

  dc = DesiredCapabilities.CHROME
  dc['loggingPrefs'] = {'driver': 'OFF', 'server': 'OFF', 'browser': 'OFF'}

  self.driver = webdriver.Chrome(chrome_options=options, desired_capabilities=dc, executable_path="C:\\path\\chromedriver.exe")

相关问题 更多 >