2017-08-04 41 views
-1

嗨,大家好,我需要幫助。如何使用硒和geckodriver設置python 3.6.2?

所以我有最新版本的蟒蛇,我能夠推動pip安裝硒。當我運行腳本它說這個消息

Traceback (most recent call last): 
    File "C:\Users\huHMONGous\Desktop\Python 3.6\Scripts\new.py", line 4, in <module> 
    driver = webdriver.Firefox() 
    File "C:\Users\huHMONGous\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__ 
    self.service.start() 
    File "C:\Users\huHMONGous\AppData\Local\Programs\Python\Python36-32\lib\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 10.我已經下載geckodriver-v0.18.0-win64zip。我提取它並複製並粘貼到用戶變量和系統變量路徑中,但它仍然不起作用。任何人都可以請幫忙?我使用記事本+ +和命令提示符下運行我的代碼

代碼我試圖運行

from selenium import webdriver 
driver = webdriver.Firefox() 
driver.get("https://www.youtube.com") 
+0

不需要說**謝謝**。當你選擇最佳**答案**作爲**解決方案**給你的問題和** Upvote **時,你說**'謝謝'**答案是**'對你有用的**。謝謝 – DebanjanB

+0

重複,一個簡單的谷歌搜索的錯誤,我發現[這](https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path)和[this](https://stackoverflow.com/questions/40188699/webdriverexception-message-geckodriver-executable-needs-to-be-in-path)。在提出問題之前,請嘗試搜索自己。 – Zcode

回答

0

這裏是回答你的問題:

當你與Selenium 3.4.3工作,geckodriver v0.18.0Mozilla Firefox 53.0Python 3.6.x綁定你可以使用下面的代碼塊來打開url https://www.youtube.com

一旦你下載並解壓可執行geckodriver,你可以在任何地方保持您的系統上,並明確要求他們在您的腳本,而無需擔心複製粘貼到User VariableSystem Variable路徑。因此,您可以按照您的要求靈活地使用多個版本的geckodriver可執行文件。

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe') 
driver = webdriver.Firefox(firefox_binary=binary, executable_path=r'C:\\Utility\\BrowserDrivers\\geckodriver.exe') 
driver.get('https://www.youtube.com') 

讓我知道這個答案是否是您的問題。