【发布时间】:2021-07-30 16:29:26
【问题描述】:
我想获取 1 个元素的类数 我有这个定位元素的代码:
url = '/v/پیش-فروش-متریال-متفاوت_پیش-فروش_تهران_افسریه_دیوار/AY7nRuql'
boz = driver.find_element_by_xpath("//*[contains(@href, '"+ url+ "')]")
然后我通过下面的代码得到它的类:
print(boz.get_attribute('class'))
我得到这个输出:kt-post-card kt-post-card--outlined kt-post-card--has-chat
我想获取页面中班级的编号,因为像上面的班级一样有24个班级
【问题讨论】:
-
实际上我想在所有页面中获取此 url 的类数,我有 24 个相同的类,我想知道与该元素匹配的类的数量,例如通过 xpath 查找元素包含这个类 kt-post-card kt-post-card--outlined kt-post-card--has-chat [0 to 23] i want the number of [0 to 23]
标签: python python-3.x selenium selenium-webdriver selenium-chromedriver