selenium - 如何在 google colab 中插入 geckodriver 的路径(环境变量)?

标签 selenium firefox path google-colaboratory geckodriver

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

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

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.

我希望 Google Colab 环境中的 selenium 能够识别 gecko 驱动程序。

最佳答案

我在这里提出了如何在 Colab 上使用 chrome+selenium 的要点。

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

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

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

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

关于selenium - 如何在 google colab 中插入 geckodriver 的路径(环境变量)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54327654/

相关文章:

javascript - 从 XUL 访问附加 SDK 'main'

css - Firefox 中缺少字体

c# - 我应该如何组合两条路径,包括向后相对路径?

javascript - 预期条件失败 : waiting for element to be clickable for element containing style ="display: none;"

python - 网页抓取和 python : Rendering javascript in html?

java - Selenium /火狐 : Command ".click()" doesn't work with a found element

php - require_once 无法打开流 : No such file or directory - even if relative path seems to be correct(? )

c# - 将文件保存到我的文档

javascript - Karma 在 Selenium 3 hub 上进行远程测试

java - 自动登录后如何将 cookie 导出到 Selenium 中的文件