如何使用selenium和geckodriver设置python 3.6.2?

如何使用selenium和geckodriver设置python 3.6.2?,python,python-3.x,selenium,geckodriver,Python,Python 3.x,Selenium,Geckodriver,嗨,伙计们,我需要帮助 因此,我有了最新版本的python,并且能够推动pip安装selenium。当我运行脚本时,它会显示以下消息 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\huHMONGo

嗨,伙计们,我需要帮助

因此,我有了最新版本的python,并且能够推动pip安装selenium。当我运行脚本时,它会显示以下消息

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.

以下是你问题的答案:

当您使用
Selenium 3.4.3
geckodriver v0.18.0
Mozilla Firefox 53.0
通过
Python 3.6.x
绑定时,您可以使用以下代码块打开url
https://www.youtube.com

下载并提取
geckodriver
可执行文件后,您可以将其保存在系统中的任何位置,并在脚本中显式调用它们,而无需担心将粘贴复制到
用户变量
系统变量
路径中。因此,您可以根据需要灵活地使用多个版本的
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')

如果这回答了您的问题,请告诉我。

无需说
谢谢
。当您选择
最佳
答案作为问题的
解决方案时,您会说
谢谢
,然后
向上投票
对您有用的答案。感谢Duplicate,一个简单的谷歌搜索的错误,我发现和。在提问之前,请试着搜索一下自己。
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')