2016-12-29 31 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') 
相關問題