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