我是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中,而它已经存在了。
有谁能帮帮我吗?
https://stackoverflow.com/questions/51388985
复制相似问题