WordPress网站建设宣传图片

Python selenium 报错: DeprecationWarning: executable_path has been deprecated, please pass in a Service object *…解决

释放双眼,带上耳机,听听看~!

错误描述: DeprecationWarning: executable_path has been deprecated, please pass in a Service object

DeprecationWarning: executable_path has been deprecated, please pass in a Service object

触发原因

DeprecationWarning 类型的警告错误:大多是属于版本已经更新,所使用的方法已经过时。

之所以出现这样的错误 是因为executable_path 被重构到了 Service 函数里,WebDriver类中加入了判断,

if executable_path != 'chromedriver':
warnings.warn('executable_path has been deprecated, please pass in a Service object',
selenium webdriver WebDriver类

原报错代码

# -*- coding: utf-8 -*-
from selenium import webdriver

def getChromeBrowser():
    # 指定浏览器内核位置
    chrome_driver = webdriver.Chrome(r'E:\chromedriver_win32\chromedriver.exe')
    return chrome_driver

修改后的代码

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

def getChromeBrowser():
    # 指定浏览器内核位置
    c_service = Service(r'E:\chromedriver_win32\chromedriver.exe')
    chrome_driver = webdriver.Chrome(service=c_service)
    return chrome_driver

这样既可解决DeprecationWarning: executable_path has been deprecated, please pass in a Service object *…的报错,再次运行,就不会再触发DeprecationWarning: executable_path has been deprecated, please pass in a Service object *…报错啦。

给TA打赏
共{{data.count}}人
人已打赏
Python异常处理Python爬虫Python笔记

python错误: Object of type * is not JSON serializable解决

2022-12-10 20:20:20

Python异常处理Python爬虫Python笔记

fake-useragent模块报错:rror occurred during loading data. Trying to use cache server解决方法

2023-3-19 15:19:40

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
展开目录