如何处理 DeprecationWarning: Executable executable_path 已弃用,请传递 i 的警告?

2026-05-24 19:021阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计303个文字,预计阅读时间需要2分钟。

如何处理 DeprecationWarning: Executable executable_path 已弃用,请传递 i 的警告?

1、错误脚本:+

如何处理 DeprecationWarning: Executable executable_path 已弃用,请传递 i 的警告?

1、错误脚本:

# 导入selenium
import time

from selenium import webdriver

# 选择谷歌浏览器
driver = webdriver.Chrome(executable_path=r'C:\Program Files\python39\chromedriver.exe')
# 输入网址
driver.get("www.baidu.com/")
# 操作网址
time.sleep(3)
# 打印网页title
print(driver.title)
# 关闭网址
driver.quit()

错误结果:

2、错误原因

出现 DeprecationWarning 警告的类型错误:

该类型的警告大多属于版本更新时,所使用的方法过时的原因;某方法在当前版本被重构,依旧可以传入参数,但是在之后的某个版本会被删除。

3、解决方案

# 导入selenium
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 选择谷歌浏览器
s = Service(executable_path=r'C:\Program Files\python39\chromedriver.exe')
driver = webdriver.Chrome(service=s)
# 输入网址
driver.get("www.baidu.com/")
# 操作网址
time.sleep(3)
# 打印网页title
print(driver.title)
# 关闭网址
driver.quit()

正确结果:

去期待陌生,去拥抱惊喜。

本文共计303个文字,预计阅读时间需要2分钟。

如何处理 DeprecationWarning: Executable executable_path 已弃用,请传递 i 的警告?

1、错误脚本:+

如何处理 DeprecationWarning: Executable executable_path 已弃用,请传递 i 的警告?

1、错误脚本:

# 导入selenium
import time

from selenium import webdriver

# 选择谷歌浏览器
driver = webdriver.Chrome(executable_path=r'C:\Program Files\python39\chromedriver.exe')
# 输入网址
driver.get("www.baidu.com/")
# 操作网址
time.sleep(3)
# 打印网页title
print(driver.title)
# 关闭网址
driver.quit()

错误结果:

2、错误原因

出现 DeprecationWarning 警告的类型错误:

该类型的警告大多属于版本更新时,所使用的方法过时的原因;某方法在当前版本被重构,依旧可以传入参数,但是在之后的某个版本会被删除。

3、解决方案

# 导入selenium
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 选择谷歌浏览器
s = Service(executable_path=r'C:\Program Files\python39\chromedriver.exe')
driver = webdriver.Chrome(service=s)
# 输入网址
driver.get("www.baidu.com/")
# 操作网址
time.sleep(3)
# 打印网页title
print(driver.title)
# 关闭网址
driver.quit()

正确结果:

去期待陌生,去拥抱惊喜。