【问题标题】:How to use Selenium on Google Colab without turning off the browser?如何在不关闭浏览器的情况下在 Google Colab 上使用 Selenium?
【发布时间】:2021-09-19 04:45:47
【问题描述】:

我尝试在 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?

【问题讨论】:

    标签: python selenium selenium-webdriver selenium-chromedriver google-colaboratory


    【解决方案1】:

    不,没有。 Google colab 用于--headless 模式。

    你不能简单地调用真实浏览器的对象。

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2020-10-08
    • 2021-11-01
    • 1970-01-01
    • 2023-03-09
    • 2016-05-10
    • 2022-01-22
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多