python-3.x 属性错误:“str”对象在selenium中没有属性“capabilities”

ki1q1bka  于 2023-10-21  发布在  Python
关注(0)|答案(3)|浏览(748)

Code screenshot1Code screenshot2
在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'
8iwquhpp

8iwquhpp1#

看看这个link,我有一个类似的问题,它引导我。试试看:

from selenium import webdriver
browser = webdriver.Chrome()
2ledvvac

2ledvvac2#

这对我很有效:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

urls = [

    'https://www.techwithtim.net/' 
        
        ]
s = Service(r"C:\Program Files (x86)\chromedriver.exe")

for url in urls:
    driver = webdriver.Chrome(service=s)
    driver.get(url)
snz8szmq

snz8szmq3#

对于当前版本的selenium,您不能直接将executable_path传递给Chrome()。如果你想引用一个特定的ChromeDriver下载版本,试试这个:

from selenium import webdriver

cService = webdriver.ChromeService(executable_path='/Users/[...]binaries(117)/chromedriver')
driver = webdriver.Chrome(service = cService)

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

相关问题