AttributeError:“str”对象在硒中没有属性“功能”

Fat*_*han 5 web-scraping python-3.x selenium-webdriver google-colaboratory

代码截图1 代码截图2

在colab中使用selenium时出现错误

我正在尝试在 colab 中使用 selenium 但它们显示属性错误

在处理上述异常的过程中,又出现了一个异常:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/common/driver_finder.py in get_path(service, options)
     38             path = SeleniumManager().driver_location(options) if path is None else path
     39         except Exception as err:
---> 40             msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
     41             raise NoSuchDriverException(msg) from err
     42 

AttributeError: 'str' object has no attribute 'capabilities'
Run Code Online (Sandbox Code Playgroud)

小智 9

对于当前版本的selenium,您无法直接将executable_path传递给Chrome()。如果您想引用 ChromeDriver 的特定下载版本,请尝试以下操作:

from selenium import webdriver

cService = webdriver.ChromeService(executable_path='/Users/[...]binaries(117)/chromedriver')
driver = webdriver.Chrome(service = cService)
Run Code Online (Sandbox Code Playgroud)

对于 Windows,请参考 .exe 本身。


小智 4

查看此链接,我遇到了类似的问题,它指导了我。尝试:

from selenium import webdriver
browser = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)