0

I am writing a parser using the selenium library, which is launched via an exe file (converted from a python script with the --windowed parameter), but when parsing starts, the chromedriver.exe console window opens, how can I prevent it from opening?

I searched for information about this, but did not find anything normal

Yurii
  • 1
  • 2

1 Answers1

0

After some digging, I found the answer to this question and the console no longer opened. All you need to do is add some code to the python script.

This will only work for Windows!!

Import the required libraries:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from subprocess import CREATE_NO_WINDOW

I also advise you to use the webdriver-manager library, it will automatically download driver updates. Let's import this library:

from webdriver_manager.chrome import ChromeDriverManager

Next, create a variable chrome_service and then assign a new flag to it:

chrome_service = ChromeService(ChromeDriverManager().install())
chrome_service.creationflags = CREATE_NO_WINDOW

And already in the driver settings we specify it:

driver = webdriver.Chrome(ChromeDriverManager().install(), service = chrome_service)

Maybe I didn’t explain very well and clearly, but everything works. It can be said that this is a better reworked of this answer - hide chromeDriver console in python

In the same place below there is essentially the same answer as I am writing here, but to close the question I answer))

Yurii
  • 1
  • 2