爬虫 – 解决 Executable path has been deprecated please pass in a Service object in Selenium Python 问题

目录

# 1. 错误描述

# 2. 错误原因

# 3. 解决方案


# 1. 错误描述

爬虫 - 解决 Executable path has been deprecated please pass in a Service object in Selenium Python 问题


# 2. 错误原因

出现 DeprecationWarning 警告的类型错误:该类型的警告大多属于版本更新时,所使用的方法过时的原因,他在当前版本被重构,还可以传入参数,但是在之后的某个版本会被删除.

查询当前版本重构后的函数,是之前的 executable_path 被重构到了 Service 函数里,如图

爬虫 - 解决 Executable path has been deprecated please pass in a Service object in Selenium Python 问题


# 3. 解决方案

# -*- coding = utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service(r"D:\pythonProject\venv\selenium\webdriver\chromedriver_97.0.4692.71\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.baidu.com')
driver.close()