为什么chrome驱动程序在ubuntu WSL中崩溃?

fnx2tebb  于 2023-05-20  发布在  Go
关注(0)|答案(1)|浏览(157)

尝试让一个简单的selenium脚本工作

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
print("options assigned")
path   = '/usr/bin/chromedriver'
browser = webdriver.Chrome(executable_path=path, options=chrome_options)

我得到这个错误:

python testscript.py
/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (1.26.15) or chardet (5.1.0)/charset_normalizer (2.0.12) doesn't match a supported version!
  warnings.warn(
options assigned
Traceback (most recent call last):
  File "/home/guc3xq/dev/chromedriverdev/testscript.py", line 14, in <module>
    browser = webdriver.Chrome(executable_path=path, options=chrome_options)
  File "/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/guc3xq/anaconda3/envs/sas/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

谷歌浏览器113.0.5672.92
我也试过降级,但不起作用
以root用户身份运行Python 3.9 Ubuntu WSL(我尝试了非root用户,但无法安装所有需要的东西)

相关问题