Python 中selenium模块报错selenium.common.exceptions.WebDriverException: Message: 'chromedriver'

selenium驱动
在使用Python 中的selenium模块时,有时会报错:

selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’
executable needs to be in PATH.

解决办法:我的解决办法是在 chromedriver下载地址 下载 chromedriver.exe ,并将其放在 Python目录下(e.g.?:\Python27)

提示:如果使用的是Windows操作系统,不管系统型号是什么,都要下载 chromedriver_win32.zip 版本
下载驱动地址:驱动地址
注意注意:下载的驱动一定要对应好自己的chrome版本
测试代码


from selenium import webdriver#导入库

browser = webdriver.Chrome()#声明浏览器
url = 'http://www.baidu.com'
browser.get(url)#打开浏览器预设网址
print(browser.page_source)#打印网页源代码
browser.close()#关闭浏览器

如果可以执行成功,跳出浏览器说明环境已经配好

发布了147 篇原创文章 · 获赞 9 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_44049466/article/details/103955748