1、chrome浏览器的版本是在更新的,要保证chrome driver驱动和浏览器版本一致,不然执行脚本会报错。
2、chrome driver驱动下载方法:
2.1 下载地址:https://chromedriver.chromium.org/downloads
2.2 查看浏览器版本
2.3 找不到匹配的驱动版本,点如下红框链接
2.3 找不到匹配的驱动版本,点如下红框链接
2.4 搜索与浏览器版本前三位一致的驱动。保证前三位一致即可
2.5 下载替换原驱动
其它:关闭google浏览器自升级功能
https://www.llqzj.net/chrome/11462.html
实操中遇到问题1---运行报错:
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path="D:\Python38\chromedriver.exe") # 使用ChromeDriver路径替换这里
解决方法:
在Selenium 4及更高版本中,推荐使用Service
对象来启动WebDriver服务。针对你的代码片段,可以按照以下方式修改:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
创建Service对象,指定ChromeDriver的路径
service = Service("D:\Python38\chromedriver.exe")
创建webdriver.Chrome实例时传入Service对象
options = webdriver.ChromeOptions()
可以在这里添加其他浏览器选项,例如无头模式等
driver = webdriver.Chrome(service=service, options=options)
然后你可以继续进行网页自动化操作...