【问题标题】:How can I insert path (environmental variable) for geckodriver in google colab?如何在 google colab 中为 geckodriver 插入路径(环境变量)?
【发布时间】:2019-06-17 01:37:23
【问题描述】:

我想通过 gecko 驱动在 Google Colab 中运行 selenium,但它告诉我:可执行文件需要在 PATH 中

我在 Google Colab 中上传了 firefox 和 gecko 驱动程序,并复制了 gecko 驱动程序的路径。该代码在我的 PC 上运行良好。

google clob 中的 firefox 和 gecko 驱动程序,但发生错误。

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support import ui
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

from selenium.common.exceptions import TimeoutException


driver =  webdriver.Firefox(executable_path=r'content/geckodriver.exe')

WebDriverException: Message: 'content/geckodriver.exe' executable needs to be in PATH.

我希望 Gecko 驱动程序应该被 Google Colab 环境中的 selenium 识别。

【问题讨论】:

  • 您是否检查过您的 selenium 版本和 Firefox 版本之间的同步条件?它们兼容吗?
  • 是的。没错。
  • 我在我的电脑上试过你的代码,它运行良好。你有什么问题?
  • 我知道。正如我在问题中已经说过的,它在我的 PC 上运行正常,但我无法在 GoogleColab 上运行它。

标签: selenium firefox path google-colaboratory geckodriver


【解决方案1】:

我在这里对如何在 Colab 上使用 chrome+selenium 做了一个要点。

https://gist.github.com/korakot/5c8e21a5af63966d80a676af0ce15067

关键是将驱动复制到PATH(这里是/usr/bin)

!cp /usr/lib/chromium-browser/chromedriver /usr/bin

您也可以尝试在那里复制您的壁虎驱动程序。但是您不能使用仅在 Windows 上运行的 exe 文件。

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
  • FileNotFoundError: [Errno 2] 没有这样的文件或目录:'chromedriver': 'chromedriver'
猜你喜欢
  • 2021-06-12
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 2018-04-04
  • 1970-01-01
  • 2020-12-06
  • 1970-01-01
  • 2017-01-23
相关资源
最近更新 更多