如何在不关闭浏览器的情况下在 Google Colab 上使用 Selenium?
How to use Selenium on Google Colab without turning off the browser?
我试图在 Google Colab 上使用 Selenium,然后发生错误。
错误消息是 "chromedriver' executable needs to be in PATH."
我用谷歌搜索并找到了解决方案。
解决方案如下:
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
当我删除 --headless
选项时,出现以下错误。
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.)
如果没有 --headless
选项,是否无法在 Google Colab 上使用 Selenium?
不,没有。 Google colab
用于 --headless
模式。
您不能简单地调用真实浏览器的对象。
我试图在 Google Colab 上使用 Selenium,然后发生错误。
错误消息是 "chromedriver' executable needs to be in PATH."
我用谷歌搜索并找到了解决方案。 解决方案如下:
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
当我删除 --headless
选项时,出现以下错误。
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.)
如果没有 --headless
选项,是否无法在 Google Colab 上使用 Selenium?
不,没有。 Google colab
用于 --headless
模式。
您不能简单地调用真实浏览器的对象。