【发布时间】:2019-08-12 08:05:53
【问题描述】:
我在 termux 中运行 ubuntu,我安装了 pycharm 来创建 python 代码。问题是我在打开 webdriver 时遇到了一些错误。
我有最新的 firefox (v59.0.2)、Selenium geckodriver v.0.24.0 并使用 python 3.6.5
这是代码
from selenium import webdriver
driver = webdriver.Firefox('/root/Downloads/geckodriver')
这是错误
Traceback (most recent call last):
File "<input>", line 3, in <module>
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 80, in __init__
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
File "/usr/lib/python3.6/shutil.py", line 309, in copytree
names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver'
如果我这样做
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/root/Downloads/geckodriver')
这是错误
Traceback (most recent call last):
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver': '/root/Downloads/geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 3, in <module>
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/root/PycharmProjects/untitled/venv/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.
【问题讨论】:
-
如果你尝试绝对路径会发生什么?
executable_path='C:/path_to_root/root/Downloads/geckodriver -
我相信C盘只适用于windows,我在termux bud中使用ubuntu。
-
驱动器是什么并不重要,这只是一个例子。
-
好吧,鉴于我真的不知道这些东西,该怎么做?我的意思是我不知道用
path_to_root替换什么。我唯一知道的是我的文件系统以 /root/ 开头
标签: python-3.x selenium firefox geckodriver termux