我是Python的新手,现在,我正在通过Al Sweigart的Automate the boring with python学习python。
现在,我想用webdriver打开一个Firefox。当我运行代码时:
from selenium import webdriver
我没有得到任何错误。但是,在运行以下命令后:
browswer=webdriver.Firefox()
我得到以下错误消息。
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/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: 'geckodriver': 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
browswer=webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/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,我一直在谷歌上滚动,试图找到解决方案。到目前为止,我已经尝试手动将geckodriver添加到/usr/local/bin。我也尝试过跑步:
brew install geckodriver
在终端上。它建议我尝试重写geckodriver,因此brew在/usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver.上安装了geckodriver
我跑过了
sudo nano /etc/paths
来查看我的路径列表,下面是列表:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver
所以我不知道为什么python告诉我geckodriver可执行文件需要在PATH中,而它已经存在了。
有谁能帮帮我吗?
发布于 2018-07-21 03:22:25
您可以将geckodriver放在Python文件夹中。当我得到同样的错误时,我就这么做了,在我把geckodriver放到Python文件夹后,一切都正常了。我已经附上了一张图片作为参考。
发布于 2019-01-31 05:03:14
我在Mac OS上遇到了与OP完全相同的问题。对我来说解决这个问题的方法是将geckodriver复制到python路径中。
特别是在终端中
which geckdriver
给出了以下路径
/usr/local/bin/geckodriver
和
which python
给出Python的路径
/Users/USERNAME/anaconda3/bin/python
然后我将geckodriver复制到python bin中。
cd /usr/local/bin/
cp geckodriver /Users/USERNAME/anaconda3/bin/
我可以从Python中调用geckodriver。
https://stackoverflow.com/questions/51388985
复制相似问题