【问题标题】:Python Selenium geckodriver required in path路径中需要 Python Selenium geckodriver
【发布时间】:2020-09-20 22:11:23
【问题描述】:
Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/bin/python/DLX/geckodriver': '/home/ubuntu/bin/python/DLX/geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 25, in <module>
    driver = webdriver.Firefox(executable_path=geckoPath,options=options)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

以上是我在尝试使用 geckodriver 和 selenium 时遇到的错误。 Geckodriver 位于路径 /home/ubuntu/bin/python/DLX/ 中,该路径已添加到 PATH var 中,我可以在使用 echo $PATH 时看到它。下面是我正在尝试运行的代码。

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver import DesiredCapabilities
from sys import platform


# setting browser to be heaadless
options = Options()
options.add_argument("--headless")
#Telling it where to find the required file
currentDir = os.path.dirname(os.path.realpath(__file__))
geckoPath = os.path.realpath(os.path.join(currentDir,'geckodriver'))
print(geckoPath)
binary = FirefoxBinary(geckoPath)
driver = webdriver.Firefox(executable_path=geckoPath,options=options)

我查看了其他帖子,尝试了他们的修复,但问题仍然存在。如果有帮助,请在 RPI3b+ Ubuntu 服务器上运行它。 硒版本=3.141.0 geckodriver ver=v0.23.0

编辑: 路径如下 /home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:/home/ ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin :/home/ubuntu/bin/python/DLX

【问题讨论】:

  • 它无法检测到 geckodriver 请确保您安装正确并设置了适当的路径
  • 包含壁虎的文件夹在PATH中,如帖子所述。

标签: python selenium selenium-webdriver


【解决方案1】:

如果您在项目中创建一次驱动程序文件夹并将 geckodriver 放在那里并提供如下所述的路径,那会很好。

假设文件夹名称是drivers

firefox_driver = "/drivers/geckodriver"
driver = webdriver.Firefox(executable_path=firefox_driver,options=options)

【讨论】:

  • 编辑它以尝试使用它,不幸的是它不起作用。
  • 你能再清楚一点“面对你”是什么意思吗?
  • 我的意思是使用我发布的方式后,是显示相同的错误还是这次错误不同
  • 错误是一样的,只是它提到的目录不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-12
  • 1970-01-01
  • 2019-06-01
  • 2017-03-05
相关资源
最近更新 更多