本文介绍了如何在Google Colab中为Geckodriver插入路径(环境变量)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过壁虎驱动程序在Google Colab中运行Selenium,但是它告诉我:可执行文件必须在PATH中

I want to run selenium in Google Colab through gecko driver, but it told me: executable needs to be in PATH

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

I uploaded firefox and gecko driver in Google Colab and copied gecko driver's path. The code worked well on my PC.

firefox和gecko驱动程序,但发生了错误.

firefox and gecko driver in google clob, but an error occurred.

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环境中被硒识别.

I want gecko driver should be known by selenium in Google Colab environment.

推荐答案

在这里,我对如何在Colab上使用铬和硒进行了总结.

I made a gist on how to use chrome+selenium on Colab here.

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

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

The key is to copy the driver to PATH (here is /usr/bin)

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

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

You can try copy your gecko driver there as well. But you cannot use the exe file which only run on Windows.

这篇关于如何在Google Colab中为Geckodriver插入路径(环境变量)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 02:25