【问题标题】:Python3 Selenium ChromeDriver Disable Extensions Logging Only Pyinstaller Windows 10Python3 Selenium ChromeDriver 禁用扩展仅记录 Pyinstaller Windows 10
【发布时间】:2018-03-20 04:01:28
【问题描述】:

我使用的是 Windows 10、Python 3.5.4、Windows Chrome 驱动程序 2.33、Selnium 3.6.0 和 Pyinstaller 3.3。

我的 Chrome 驱动程序扩展程序会向控制台生成日志记录,这似乎是由 Chrome 中的扩展程序引起的。

(我已尝试使用 chrome_options.add_argument("--disable-extensions") 并且日志记录不明显)

我想继续使用 Chrome 扩展程序,但我只想禁用此日志记录。

在我可以禁用此日志记录之前,我无法在没有控制台的情况下创建 pyinstaller.exe。

关于如何仅禁用 selenium chrome 驱动程序扩展日志记录的任何建议?或者在 Python 中使用 pyinstaller 在没有控制台的情况下创建 exe 来玩得很好?

感谢您的宝贵时间。

# Python Script Parameters for chrome driver.

# example.py

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-logging")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-default-apps")
chrome_options.add_argument('--user-data-dir=C:\\Users\\testuser\\AppData\\Local\\Google\\Chrome\\User Data')

driver = webdriver.Chrome(r"D:\Selenium\chromedriver_win32\chromedriver.exe", chrome_options=chrome_options)

【问题讨论】:

  • 这里有同样的问题。我还没有找到如何禁用它呢

标签: python selenium pyinstaller


【解决方案1】:

如果你想禁用控制台,你应该修改 webdriver 文件 service.py 的源代码。文件C:\Python27\Lib\site-packages\selenium\webdriver\common\service.py 的示例路径 从 第 69 行 更改为此。

try:
        cmd = [self.path]
        cmd.extend(self.command_line_args())

        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

        self.process = subprocess.Popen(cmd, env=self.env, startupinfo=startupinfo,
                                        close_fds=platform.system() != 'Windows',
                                        stdout=self.log_file, stderr=self.log_file)
    except TypeError:
        raise

然后,当您构建应用并运行时,Chromedriver 控制台将不会显示。

【讨论】:

    猜你喜欢
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2016-07-14
    相关资源
    最近更新 更多