爬虫 - 解决 Executable path has been deprecated please pass in a Service object in Selenium Python 问题
使用 Selenium 时,将 chromedriver.exe 路径传入 executable_path 参数时,出现该错误,不影响运行,其他解决方案都是 import warnings 模块然后 ignore 掉,治标不治本,这其实是版本改动的原因. _ DeprecationWarning 类警告
·
目录
# 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()
更多推荐
已为社区贡献1条内容
所有评论(0)