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 :)
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
When I add the parameter creationflags=CREATE_NO_WINDOW it gives the following error:
unresolved reference 'CREATE_NO_WINDOW'
Do you know why?
I forget to mention the import,so at top of file where imports are add:
from win32process import CREATE_NO_WINDOW
I'm still getting this printed out:
DevTools listening on ws://127.0.0.1:51584/devtools/browser/41c22445-3e1d-408a-bc12-a678ecce15fd
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
Output:
C:\code\bs
λ python chrome_stock.py
DevTools listening on ws://127.0.0.1:62452/devtools/browser/c3c1f10a-9475-4bd7-97a0-418c7366b0d8
0.16
C:\python37\python.exe
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.py
Now run again,and there is no
DevTools listening
.
Output:
C:\code\bs
λ python chrome_stock.py
0.16
C:\python37\python.exe
I'm sorry but i don't really understand what you're saying or doing. Could you maybe try to explain again? :)
You could run code that i have posted or add this to your code that run Selenium.
import sys
print(sys.executable)
Output:
C:\python37\python.exe
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.
(Feb-29-2020, 04:48 PM)snippsat Wrote: [ -> ]I forget to mention the import,so at top of file where imports are add:
from win32process import CREATE_NO_WINDOW
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