Python FileNotFound:[WinError 2]系统找不到指定的文件”;使用selenium时出错

Python FileNotFound:[WinError 2]系统找不到指定的文件”;使用selenium时出错,python,python-3.x,selenium,selenium-webdriver,Python,Python 3.x,Selenium,Selenium Webdriver,我使用Windows pro 10,使用Firefox执行python selenium程序。 正在尝试运行: from selenium import webdriver wb = webdriver.Firefox() wb.get("https://stackoverflow.com") 获取以下错误(请忽略错误消息中的web浏览器): 回溯(最近一次呼叫最后一次): 文件“C:\Users\dilri\AppData\Local\Programs\Python\P

我使用Windows pro 10,使用Firefox执行python selenium程序。 正在尝试运行:

from selenium import webdriver
wb = webdriver.Firefox()
wb.get("https://stackoverflow.com")

获取以下错误(请忽略错误消息中的web浏览器):

回溯(最近一次呼叫最后一次):
文件“C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py”,第74行,开始
stdout=self.log\u文件,stderr=self.log\u文件)
文件“C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py”,第707行,在uu init中__
恢复信号,启动新会话)
文件“C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py”,第990行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]系统找不到指定的文件
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“H:\temp.py”,第2行,在
driver=webdriver.Chrome()
文件“C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py”,第62行,在\uu init中__
self.service.start()
文件“C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py”,第81行,开始
os.path.basename(self.path)、self.start\u错误消息)
selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要位于路径中。请看https://sites.google.com/a/chromium.org/chromedriver/home

正如错误消息中明确提到的,首先安装适当的浏览器驱动程序,并给出其到
系统变量的路径。
就我而言:

from selenium import webdriver
driver_path = r"G:\Python\geckodriver.exe" #since on windows use raw strings 
wb = webdriver.Firefox(executable_path=driver_path)

# to check if it's working
wb.get("https://stackoverflow.com")

请记住:驱动程序路径必须是原始字符串,因为我们正在windows上工作。
另外,请注意不要将文件名指定为selenium.py,正如错误消息中明确提到的那样,首先安装适当的浏览器驱动程序并将其路径指定给
系统变量
路径。 就我而言:

from selenium import webdriver
driver_path = r"G:\Python\geckodriver.exe" #since on windows use raw strings 
wb = webdriver.Firefox(executable_path=driver_path)

# to check if it's working
wb.get("https://stackoverflow.com")

请记住:驱动程序路径必须是原始字符串,因为我们正在windows上工作。 另外,请注意不要将文件名指定为selenium.py