我只想用Selify编写一个Hello World,并编写以下代码:

from selenium import webdriver
driver = webdriver.Chrome('C:/Users/[...]/chromedriver/chromedriver.exe')
driver.get("https://www.google.com")

但我一直收到以下错误:

Traceback (most recent call last):
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 75, in driver_location
    browser = options.capabilities["browserName"]
              ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'capabilities'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\[...]\ets.py", line 3, in <module>
    driver = webdriver.Chrome('C:/Users/[...]/chromedriver/chromedriver.exe')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 40, in get_path
    msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
                                         ^^^^^^^^^^^^^^^^^^^^

我正在使用Chrome版本:119.0.6045.200 和ChromeDriver:119.0.6045.105

我在上面找不到任何东西,谢谢你的帮助

推荐答案

您可以通过以下方式简单地获取驱动程序:

from selenium import webdriver

driver = webdriver.Chrome()

然后:

driver.get("https://www.google.com")

你不再需要driver.exe美元了

DOC:https://www.selenium.dev/blog/2022/introducing-selenium-manager/

Python相关问答推荐

如何使用Python中的clinicalTrials.gov API获取完整结果?

从包含数字和单词的文件中读取和获取数据集

Python多处理:当我在一个巨大的pandas数据框架上启动许多进程时,程序就会陷入困境

如何使用Python将工作表从一个Excel工作簿复制粘贴到另一个工作簿?

max_of_three使用First_select、second_select、

scikit-learn导入无法导入名称METRIC_MAPPING64'

pandas滚动和窗口中有效观察的最大数量

聚合具有重复元素的Python字典列表,并添加具有重复元素数量的新键

如何在polars(pythonapi)中解构嵌套 struct ?

加速Python循环

如何从.cgi网站刮一张表到rame?

如何在solve()之后获得症状上的等式的值

无法使用DBFS File API路径附加到CSV In Datricks(OSError Errno 95操作不支持)

以逻辑方式获取自己的pyproject.toml依赖项

为什么常规操作不以其就地对应操作为基础?

导入错误:无法导入名称';操作';

用SymPy在Python中求解指数函数

为什么Python内存中的列表大小与文档不匹配?

处理Gekko的非最优解

Python Mercury离线安装