【发布时间】: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