Python中遇到selenium.common.exceptions.WebDriverException问题,解决办法

在pycharm中运行程序:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

出现问题下面问题:
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Python中遇到selenium.common.exceptions.WebDriverException问题,解决办法_第1张图片

解决方法:

  1. 查看浏览器的版本
    这里我用的是chrome浏览器,在浏览器中输入

chrome://version/
Python中遇到selenium.common.exceptions.WebDriverException问题,解决办法_第2张图片

  1. 下载合适的自己浏览器版本的driver
    进入网站 http://chromedriver.storage.googleapis.com/index.html 下载适合自己浏览器的driver
    Python中遇到selenium.common.exceptions.WebDriverException问题,解决办法_第3张图片

  2. 两种解决方法(原理都是一样的)

  • 第一种方法直接将下载好的文件是一个压缩包,解压后,放在程序目录中。

  • 第二种方法是设置参数executable_path,比如这里我将chromedriver.exe放在目录

C:\Users\19248\Desktop\安装缓存

如下
在这里插入图片描述
Python中遇到selenium.common.exceptions.WebDriverException问题,解决办法_第4张图片

你可能感兴趣的:(遇到的问题,编程语言,python基础,细节)