简体   繁体   English

Python Selenium 路径中需要壁虎驱动程序

[英]Python Selenium geckodriver required in path

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.

The above is the error I am getting while trying to use geckodriver and selenium.以上是我在尝试使用 geckodriver 和 selenium 时遇到的错误。 Geckodriver is in the path /home/ubuntu/bin/python/DLX/, that path has been added to the PATH var and I can see it when using echo $PATH. Geckodriver 在路径 /home/ubuntu/bin/python/DLX/ 中,该路径已添加到 PATH var 中,我可以在使用 echo $PATH 时看到它。 Below is the code I'm trying to get running.下面是我试图运行的代码。

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)

I've looked at other posts, tried their fixes and I've still got the issue.我查看了其他帖子,尝试了他们的修复,但我仍然遇到了问题。 Running it on RPI3b+ Ubuntu server if that helps.如果有帮助,请在 RPI3b+ Ubuntu 服务器上运行它。 Selenium Ver=3.141.0 geckodriver ver=v0.23.0 Selenium Ver=3.141.0 geckodriver ver=v0.23.0

Edit: PATH is as follows /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编辑:PATH如下/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/游戏:/snap/bin:/home/ubuntu/bin/python/DLX

It would be fine if you create once driver folder in you project and place geckodriver there and provide path as mentioned below.如果您在项目中创建一次驱动程序文件夹并将 geckodriver 放在那里并提供如下所述的路径,那会很好。

Lets say folder name is drivers假设文件夹名称是drivers

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium Geckodriver 应该在 PATH 中 - Python Selenium Geckodriver should be in PATH Python Selenium“&#39;geckodriver&#39;可执行文件必须在PATH中” - Python Selenium “ 'geckodriver' executable needs to be in PATH” Selenium 使用 Python - Geckodriver 可执行文件需要在 PATH 中 - Selenium using Python - Geckodriver executable needs to be in PATH Mac 上的 Selenium in Python - Geckodriver 可执行文件需要在 PATH 中 - Selenium in Python on Mac - Geckodriver executable needs to be in PATH Selenium和Geckodriver的路径问题 - Path issues with Selenium and Geckodriver Selenium 和 python:“消息:&#39;geckodriver&#39; 可执行文件需要在 PATH 中。” - Selenium and python : "Message: 'geckodriver' executable needs to be in PATH. " Python Selenium 和 FireFox \\ geckodriver - Python Selenium and FireFox \ geckodriver Python 3:Selenium和geckodriver错误? - Python 3: Selenium & geckodriver error? python - selenium 给出错误 geckodriver 需要在 PATH 中(即使它是) - python - selenium give error tht geckodriver need to be in PATH (even though IT IS) python selenium geckodriver - 可执行文件需要在 PATH 中/如何在 armbian buster 上安装 - python selenium geckodriver - executable needs to be in PATH / how to install on armbian buster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM