chrome-driver安装

在自动化测试和网络爬虫开发中,chromedriver是连接 Selenium 与 Chrome 浏览器的核心桥梁。然而,安装过程中版本不匹配、路径配置错误等问题常常让人头疼。本文从实战出发,手把手教你如何快速安装并验证 ChromeDriver,避开常见“坑点”!

一、安装前的准备

  1. 安装 Chrome 浏览器
  2. 查看 Chrome 版本
    打开 Chrome 浏览器,输入 chrome://settings/help 查看版本号(如 108.0.5359.125)版本号的前三位需与 ChromeDriver 完全一致(例如 108.0.5359.x)

二、下载与安装 ChromeDriver

https://googlechromelabs.github.io/chrome-for-testing/

三、编写程序验证

1
2
3
4
5
6
7
8
9
from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = 'chrome path'

driver = webdriver.Chrome(executable_path='chromedriver path', options=options)
driver.get("https://www.baidu.com")
driver.maximize_window()
driver.quit()