提问人:Mahdi_J 提问时间:7/28/2019 最后编辑:furasMahdi_J 更新时间:11/17/2023 访问量:2597
Google Colab 上的 WebDriver 异常:Chrome 无法启动,退出异常
webdriver exception on google colab: chrome failed to start, exited abnormally
问:
我已经阅读了几个关于这个问题的帖子,但没有一个真正帮助我,所以就这样吧。我正在尝试在 google colab 上使用 selenium webdriver。我在安装它时遇到了一些问题,但最终使用下面的代码,我能够安装它:
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get("https://www.webite-url.com")
但是,现在当我运行这两行代码时:
from selenium import webdriver
driver = webdriver.Chrome()
这是我收到的错误:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
答:
1赞
furas
7/29/2019
#1
它在没有视频卡和显示器的服务器上运行,因此您必须始终使用,也许还有其他选项--headless
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)
driver.get("...your_url...")
评论
headless
headless
webdriver.Chrome()
webdriver.Chrome('chromedriver',chrome_options=chrome_options)
chrome_options
--headless
webdriver.Chrome()