python-3.x - DeprecationWarning: executable_path has been deprecated, please pass in a Service object
问题描述
我今天开始了一个 selenium 教程,并在尝试运行代码时遇到了这个错误。我尝试了其他方法,但最终得到了同样的错误。我在使用 VSC 的 MacOS 上。
我的代码:
from selenium import webdriver
PATH = '/Users/blutch/Documents/Chrom Web Driver\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com")
我也试过在 /Users 前面插入 C:。谁能指导我为什么会发生这种情况/如何解决它?
解决方案
此错误消息...
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
...意味着该密钥 executable_path
将在即将发布的版本中被弃用。
此更改与Selenium 4.0 Beta 1 更改日志一致,其中提到:
弃用驱动程序实例化中除
Options
和参数之外的所有参数。Service
(#9125,#9128)
解决方案
弃用密钥 后,executable_path
您必须使用Service()
该类的实例,如下所示:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=s)
TL; 博士
您可以在以下位置找到一些相关的详细讨论:
推荐阅读
- php - Codeiginiter - 从用户输入验证并检查数据是否存在于两个表中
- python - 网页抓取后将一种表数据转换为整数用于 if/else 语句
- elasticsearch - Elasticsearch:对内部点击进行排序
- angular - Angular updateTag 函数不会更新源视图 HTML 中的元标记
- sql - Postgresql/SQL 基于多列值插入表
- python - 如何在 Mac OS 上安装 pykaldi?
- python-3.x - 想要从字符串列创建列表
- spring - 带有 Rest API 404 的 Spring Boot
- sql - 如果发生更改,检查数据并禁用以前的记录并插入新的
- twitter-bootstrap-3 - FontAwesome 5 在 SmartAdmin 模板中使用 Bootstrap 复选框