使用 pyinstaller 摆脱 chromedirver 控制台窗口

Ahm*_*Was 2 python selenium pyinstaller python-3.x selenium-chromedriver

我在无头模式下使用 chromedriver 。我使用 pyinstaller 将脚本编译为一个 exe 文件。一切正常,除了每次打开 chrome 页面时都会出现以下控制台窗口

在此处输入图片说明

我已经--windowed单独、--noconsole单独--windowed--noconsole一起尝试了这些选项,但我仍然得到了这个窗口。

我怎样才能摆脱它?

Ahm*_*Was 6

我能够找到以下答案,它对我来说非常有效:

为避免获得 chromedriver 的控制台窗口,请打开文件

Python\Lib\site-packages\selenium\webdriver\common\service.py

和改变

self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)
Run Code Online (Sandbox Code Playgroud)

到:

self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE ,stderr=PIPE, shell=False, creationflags=0x08000000)
Run Code Online (Sandbox Code Playgroud)