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

# 1. 错误描述


# 2. 错误原因

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

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


# 3. 解决方案

# -*- coding = utf-8 -*-
# @Time : 2021/10/16 17:47
# @Author : LIUYU
# @File : test_selenium.py
# @Software : PyCharm
 
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
 
s = Service(r"D:\Software\webdrivers\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.baidu.com')
driver.close()

转自:https://www.dianjilingqu.com/

posted @ 2022-05-01 11:24  元宇宙-Metaverse  阅读(453)  评论(0)    收藏  举报