python - 如何将 geckodriver 放入 PATH?

标签 python selenium selenium-webdriver geckodriver

<分区>

我在 OS Sierra 上运行 Python 3.5.2。我安装了 selenium,并且正在关注一本名为“使用 Python 自动化无聊任务”的书

我的代码是

from selenium import webdriver
>>> browser = webdriver.Firefox()

我一直收到错误

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

我已经广泛搜索了我的问题的解决方案。很多人都有同样的问题。。但是没有一个解决方案有效。我在我的 Python 文件夹中随处复制了 geckodriver。我试过使用终端,我试过在代码中指定路径,但它仍然给我错误。我希望有人能帮助我。很抱歉,如果格式错误,我不知道自己在做什么。

最佳答案

我遇到了同样的问题,下面是我解决它的方法:

  1. here 下载geckodriver
  2. 解压缩并将geckodriver文件移动到/usr/local/bin/目录
  3. 使用 selenium Firefox webdriver 运行 python 程序。

关于python - 如何将 geckodriver 放入 PATH?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40388503/

相关文章:

c# - Selenium 无法在此站点上找到元素

selenium - Selenium 是否有相对的 CSS 定位器?

python - 如何使用 Python 字符串加载 PhantomJS

java - 如何从一个类调用另一类的屏幕截图方法?如何在导航到我的代码后截取主页屏幕截图?

selenium-webdriver - 测试失败后 webdriver 的超时问题和陈旧实例

python - 创建新文件并将其包含到 python 包中

python - 写 csv 头从下面写的 numpy 数组中删除数据

python - ElementClickInterceptedException : element click intercepted:

python - 如何按这两个值对元组列表进行排序?

python - xoauth.py IMAP token 在 1 小时后过期