This question is absolutely the same as this. But solutions there are not working for me :(
I'm using undetected-chromedriver
, webdriver-manager
and trying to put selenium scrapper behind the scene of PyQT5
app which i build with pyinstaller
- First i tried this answer by @Ali Sajjad. Trying set
self.creationflags = CREATE_NO_WINDOW
inService
object. I added prints to see changes.
import undetected_chromedriver.v2 as uc
from selenium.webdriver.common.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Scrapper:
def __init__(self):
self.driver = None
self.page_load_time_out = 20
def get_driver(self):
# options = webdriver.ChromeOptions()
options = uc.ChromeOptions()
...
chrome_service = Service(ChromeDriverManager().install())
# try except block because import raising error not on windows machines
print(chrome_service.creationflags)
try:
from subprocess import CREATE_NO_WINDOW
chrome_service.creationflags = CREATE_NO_WINDOW
except ImportError:
pass
print(chrome_service.creationflags)
driver = uc.Chrome(
options=options,
service=chrome_service
)
self.driver = driver
print(self.driver.service.creationflags)
def get_page(self, url):
self.get_driver()
print(self.driver.service.creationflags)
self.driver.set_page_load_timeout(self.page_load_time_out)
self.driver.get(url)
...
1) Console output:
0
134217728
0
0
- Next step by me setting
self.driver.service.creationflags = CREATE_NO_WINDOW
. Added# difference
.
import undetected_chromedriver.v2 as uc
from selenium.webdriver.common.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Scrapper:
def __init__(self):
self.driver = None
self.page_load_time_out = 20
def get_driver(self):
# options = webdriver.ChromeOptions()
options = uc.ChromeOptions()
...
chrome_service = Service(ChromeDriverManager().install())
# try except block because import raising error not on windows machines
print(chrome_service.creationflags)
try:
from subprocess import CREATE_NO_WINDOW
chrome_service.creationflags = CREATE_NO_WINDOW
except ImportError:
pass
print(chrome_service.creationflags)
driver = uc.Chrome(
options=options,
service=chrome_service
)
self.driver = driver
# difference !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
try:
from subprocess import CREATE_NO_WINDOW
self.driver.service.creationflags = CREATE_NO_WINDOW
except ImportError:
pass
print(self.driver.service.creationflags)
def get_page(self, url):
self.get_driver()
print(self.driver.service.creationflags)
self.driver.set_page_load_timeout(self.page_load_time_out)
self.driver.get(url)
...
2) Console output:
0
134217728
134217728
134217728
So in my opinion it should works (cmd window of undetected-chromedriver should not open) now because value of creationflags changed
, BUT IT'S NOT WORKING... still see this:
- Then i tried this solution from same question...Just did the same thing like in soulution in source code of
selenium.webdriver.common.service
and It's working but only on mine machine. If i share my app.exe, other people can't even run the script. They press button and app become frozen. But on my PC it's working, i don't see console by undetected-chromedriver.
Any help please. I'm building this app on virtual box's windows, it's painful enough if do this too long...
ImportError
here? TheCREATE_NO_WINDOW
flag is definitely available in windows. – RenounceImportError
. Anyway it doesn't matter because it is constant and i can see that i'm getting it with prints. Thanks for reply – Brio