首页 > 编程语言> > 解决 DeprecationWarning: Executable executable_path has been deprecated, please pass in a Service obje
解决 DeprecationWarning: Executable executable_path has been deprecated, please pass in a Service obje
作者:互联网
1、错误脚本:
# 导入selenium import time from selenium import webdriver # 选择谷歌浏览器 driver = webdriver.Chrome(executable_path=r'C:\Program Files\python39\chromedriver.exe') # 输入网址 driver.get("https://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("https://www.baidu.com/") # 操作网址 time.sleep(3) # 打印网页title print(driver.title) # 关闭网址 driver.quit()
正确结果:
标签:webdriver,Executable,DeprecationWarning,Service,title,selenium,driver,网址,import 来源: https://www.cnblogs.com/hls-code/p/15762958.html