selenium prints weird things... - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: selenium prints weird things... (/thread-24626.html) |
selenium prints weird things... - julio2000 - Feb-23-2020 So as soon as I start a selenium browser with selenium webdriver, it prints out this: DevTools listening on ws://127.0.0.1:61823/devtools/browser/b8d83e7c-b8d3-4158-9c46-b707ec73b7e9 Is it possible to avoid printing this out? cause it doesn't look good in my program :) RE: selenium prints weird things... - snippsat - Feb-23-2020 The best way is to take it source code,as other ways have changed or not working anymore. root python\Lib\site-packages\selenium\webdriver\common\service.py In service.py add creationflags=CREATE_NO_WINDOW parameter.def start(self): """ Starts the Service. :Exceptions: - WebDriverException : Raised either when it can't start the service or when it can't connect to the service """ try: cmd = [self.path] cmd.extend(self.command_line_args()) self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE, creationflags=CREATE_NO_WINDOW) except TypeError: raise RE: selenium prints weird things... - julio2000 - Feb-29-2020 When I add the parameter creationflags=CREATE_NO_WINDOW it gives the following error: unresolved reference 'CREATE_NO_WINDOW' Do you know why? RE: selenium prints weird things... - snippsat - Feb-29-2020 I forget to mention the import,so at top of file where imports are add: from win32process import CREATE_NO_WINDOW RE: selenium prints weird things... - julio2000 - Feb-29-2020 I'm still getting this printed out: DevTools listening on ws://127.0.0.1:51584/devtools/browser/41c22445-3e1d-408a-bc12-a678ecce15fd RE: selenium prints weird things... - snippsat - Feb-29-2020 Are sure you execute right Python interpreter,here at test an added sys.executable output.from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup import time, sys #--| Setup options = Options() options.add_argument("--headless") options.add_argument('--disable-gpu') options.add_argument('--log-level=3') browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options) #--| Parse or automation browser.get('https://www.morningstar.com/stocks/XOSL/XXL/quote.html') time.sleep(1) soup = BeautifulSoup(browser.page_source, 'lxml') bid_size = soup.select('div.dp-value.price-down.ng-binding.ng-scope') price_sales = soup.select('li:nth-child(9) > div > div.dp-value.ng-binding') print(price_sales[0].text.strip()) print(sys.executable) Now have i comment out #creationflags=CREATE_NO_WINDOW As the path is C:\python37 I will open file like this and remove comment and and save service.py .C:\code\bs λ vim C:\python37\Lib\site-packages\selenium\webdriver\common\service.pyNow run again,and there is no DevTools listening .
RE: selenium prints weird things... - julio2000 - Mar-01-2020 I'm sorry but i don't really understand what you're saying or doing. Could you maybe try to explain again? :) RE: selenium prints weird things... - snippsat - Mar-01-2020 You could run code that i have posted or add this to your code that run Selenium. import sys print(sys.executable) This will give the root to the Python interpreter that is used.Then the changes for me should be done here. C:\python37\Lib\site-packages\selenium\webdriver\common\ service.py If i had used virtual environment,Anaconda,ect... it would have point to a other Python interpreter, the i would have needed to make changes there. Then as posted open service.py and add creationflags=CREATE_NO_WINDOW and save.Run code again and see if DevTools listening is gone.
RE: selenium prints weird things... - drain3r - May-24-2021 (Feb-29-2020, 04:48 PM)snippsat Wrote: I forget to mention the import,so at top of file where imports are add: Hey there, sorry to open up an old thread but I get ModuleNotFoundError: No module named 'win32process'after adding in your import statement. Unable to find this module anywhere.. Thanks. EDIT: Delete my post, spoke too soon! If anyone else has the same problem as me it's import subprocess from subprocess import CREATE_NO_WINDOW |