2

我正在尝试在 Google Colab 中使用 Selenium,但是当我尝试运行 Firefox 实例时出现一些错误。我跟着这个链接:

  • Selenium 文档在这里,我尝试使用驱动程序管理软件,但我得到了错误,说无法找到 Firefox 的二进制位置,所以我点击这个其他链接,但我无法让它运行

所以我尝试了硬编码位置,但我得到了错误:

Message: 'geckodriver' executable needs to be in PATH.

我实际上下载了 geckodrive 并点击此链接

我已将 grecodriver 上传到我的云端硬盘并使用 google.colab 库进行访问,但我总是收到错误消息:

No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver'

这是我的代码:

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from google.colab import drive

drive.mount('/content/drive', force_remount=True)

service = FirefoxService(executable_path= '/content/drive/MyDrive/Santillana/geckodriver')
driver = webdriver.Firefox(service=service)

我的驱动器文件

整个错误:

---------------------------------------------------------------------------

FileNotFoundError                         Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stdin=PIPE,
---> 76                                             creationflags=self.creationflags)
     77         except TypeError:

4 frames

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver': '/content/drive/MyDrive/Santillana/geckodriver'


During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

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

4

1 回答 1

1

此错误消息...

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver': '/content/drive/MyDrive/Santillana/geckodriver'

...意味着您的程序无法找到GeckoDriver可执行文件。


分析

根据错误消息,您似乎在系统上。但是,您已经下载了版本的GeckoDriver

已下载


解决方案

您可能需要下载Linux版本的GeckoDriver可执行文件,而不是Windows版本的GeckoDriver 。

于 2022-01-24T15:49:11.110 回答