Python geckodriver 可执行文件需要在路径中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40048940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
geckodriver executable needs to be in path
提问by HearthQiu
I have read previous questions asked on this topic and tried to follow the suggestions but I continue to get errors. On terminal, I ran
我已阅读有关此主题的先前问题并尝试遵循建议,但我仍然遇到错误。在终端上,我跑了
export PATH=$PATH:/Users/Conger/Documents/geckodriver-0.8.0-OSX
I also tried
我也试过
export PATH=$PATH:/Users/Conger/Documents/geckodriver
When I run the following Python code
当我运行以下 Python 代码时
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/Users/Conger/Documents/Firefox.app'
driver = webdriver.Firefox(capabilities=firefox_capabilities)
I still get the following error
我仍然收到以下错误
Python - testwebscrap.py:8
Traceback (most recent call last):
File "/Users/Conger/Documents/Python/Crash_Course/testwebscrap.py", line 11, in <module>
driver = webdriver.Firefox(capabilities=firefox_capabilities)
File "/Users/Conger/miniconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/Users/Conger/miniconda2/lib/python2.7/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.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1006df6d0>> ignored
[Finished in 0.194s]
回答by sottany
you may downgrade your selenium by
你可以通过以下方式降级你的硒
pip install selenium==2.53.6
pip 安装硒==2.53.6
This has solved my issue
这解决了我的问题
回答by Avatazjoe
On mac:
在 Mac 上:
brew install geckodriver
Homebrew is the most popular package manager for Mac OS X, you will need install XCode on your mac and it will be then accesible from your terminal.
Homebrew 是最流行的 Mac OS X 包管理器,你需要在你的 Mac 上安装 XCode,然后可以从你的终端访问它。
You can follow this tutorialif required
如果需要,您可以按照本教程进行操作
回答by Hymanssn
回答by zzy
First we know that gekodriver is the driver engine of Firefox,and we know that
driver.Firefox()
is used to open Firefox browser, and it will call the gekodriver engine ,so we need to give the gekodirver a executable permission.
so we download the latest gekodriver uncompress the tar packge ,and put gekodriver at the /usr/bin/
ok,that's my answer and i have tested.
首先我们知道gekodriver是Firefox的驱动引擎,我们知道它
driver.Firefox()
是用来打开火狐浏览器的,它会调用gekodriver引擎,所以我们需要给gekodirver一个可执行权限。所以我们下载最新的 gekodriver 解压缩 tar 包,然后把 gekodriver 放在/usr/bin/
ok 上,这就是我的答案,我已经测试过了。
回答by Shabahat M. Ayubi
export path works only in the terminal you have entered the command. If you try to run the script from a different terminal, you will get the same error.
导出路径仅在您输入命令的终端中有效。如果您尝试从不同的终端运行脚本,您将收到相同的错误。