我正在尝试在 Google Colab 中使用 Selenium,但是当我尝试运行 Firefox 实例时出现一些错误。
我点击了这个链接:
-
硒文档 https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/在这里,我尝试使用驱动程序管理软件,但收到错误消息,指出无法找到 Firefox 的二进制位置,所以我按照另一个link https://stackoverflow.com/questions/66000401/expected-browser-binary-location-but-unable-to-find-binary-in-default-location/66000618#66000618,但我无法让它运行
所以我尝试使用硬编码位置,但出现错误:
Message: 'geckodriver' executable needs to be in PATH.
我实际上下载了 geckodrive 并按照此操作link https://stackoverflow.com/questions/40302006/no-such-file-or-directory-geckodriver-for-a-simple-selenium-application-in-py
我已将 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.