2016-12-29 66 views
0

我正在通过“使Python自动化枯燥的东西”,并运行带有运行OS X v.10.9.5的Mac的Python 3.6。我的Firefox版本是50.0。在Mac上使用Python和Firefox的selenium webdriver的问题

每当我输入(每在第11章中的说明):

>>> from selenium import webdriver 
>>> browser = 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 74, in start 
    stdout=self.log_file, stderr=self.log_file) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in __init__ 
    restore_signals, start_new_session) 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, 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#18>", line 1, in <module> 
    browser = webdriver.Firefox() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__ 
    self.service.start() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 81, in start 
    os.path.basename(self.path), self.start_error_message) 
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

我已搜查在本网站和其他这个错误,但最提供的解决方案是特定于Windows的(包括下面评论中引用的帖子),或者在应用时似乎不适用于我的Mac机器。

我应该做什么的建议?

请记住,我是一个总新手,所以不熟悉终端。预先感谢您的帮助。

+1

的[使用Python硒可能的复制 - Geckodriver可执行文件需要在PATH](http://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – martianwars

+0

正如我在我的帖子中提到的,我没有检查这个网站上的主题以前的帖子,并尝试在帖子上提供您的参考解决方案,但没有与他们取得任何成功。 引用的帖子来自Windows用户,而我正在使用Mac。此外,该线索中的发布说明明确要求海报发布答案,而不是澄清要求或其他问题。 – Oligarch

+0

您是否尝试过其中一条评论? “在Mac上:'brew install geckodriver'”? – martianwars

回答

0

谢谢你的回复。

%的意见,安装自制软件和运行

brew install geckodriver 

命令没有单独解决的问题。重启终端也没有解决问题。

我在其他几篇文章中发现了一些问题,并尝试通过Mac Finder打开/ usr/bin和/ usr/local/bin文件,并手动将geckodriver文件复制到文件夹中。我第一次进入:

browser = webdriver.Firefox() 

到Python IDLE,我得到了以下警告/异常:

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x101a960b8>> 
Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 173, in __del__ 
    self.stop() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 145, in stop 
    if self.process is None: 
AttributeError: 'Service' object has no attribute 'process' 
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1071b3eb8>> 
Traceback (most recent call last): 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 173, in __del__ 
    self.stop() 
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 145, in stop 
    if self.process is None: 
AttributeError: 'Service' object has no attribute 'process' 

,但浏览器中打开。当我再次运行它时,我能够像书中一样遵守,没有任何错误或例外。

看来,这工作。但是,通过Mac查找器而不是终端来完成所有这一切感觉不对。我对这一切还是很陌生的,所以如果我做了什么会损害我的系统,我会很欣赏任何指针。谢谢你的帮助。

1

我钻研了的webdriver与Firefox的驱动程序的源代码:我不得不放弃火狐()构造函数的geckodriver二进制的直接通道,就像

self.browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver') 
相关问题