报错提示:

selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for firefox using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

意思就是找不到驱动火狐浏览器的webdriver,网络上回答的方法一般是:

1.更新selenium

2.如果是webdriver和浏览器有版本对应(如:谷歌)则需要下载对应的浏览器版本,但是火狐浏览器不在此列

3.指定webdriver路径(这就是本文提供的解决方案,来源于python - selenium.common.exceptions.NoSuchDriverException: 消息:无法使用Selenium Manager获取chromedriver,使用Selenium和ChromeDriver时出错 - 堆栈溢出 (stackoverflow.com))

本文提供的解决方案:

使用selenium的service,指定webdriver的路径,案例如下

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.chrome.service import Service

#webdriver的路径

gecko_driver_path = 'C:\All\software\Anaconda\geckodriver.exe'

#固定搭配直接用就行了

service = Service(executable_path=gecko_driver_path)

driver = webdriver.Firefox(service=service)

# 打开网页

driver.get("https://www.baidu.com")

bingo,成功解决了!

相关链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: