在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
解决方法:
- 查看浏览器的版本
这里我用的是chrome浏览器,在浏览器中输入
chrome://version/
-
下载合适的自己浏览器版本的driver
进入网站 http://chromedriver.storage.googleapis.com/index.html 下载适合自己浏览器的driver
-
两种解决方法(原理都是一样的)
- 第一种方法直接将下载好的文件是一个压缩包,解压后,放在程序目录中。
- 第二种方法是设置参数executable_path,比如这里我将chromedriver.exe放在目录
C:\Users\19248\Desktop\安装缓存
如下
在这里插入图片描述