Selenium查找特定元素:CLASS_NAME='weui-desktop-icon__date'且accessible_name不为空
要使用Selenium找到CLASS_NAME='weui-desktop-icon__date'并且元素accessible_name属性不为空的元素,可以使用以下代码:
from selenium import webdriver
# 启动浏览器
driver = webdriver.Chrome()
# 打开网页
driver.get('https://example.com')
# 找到所有符合条件的元素
elements = driver.find_elements_by_css_selector('.weui-desktop-icon__date[accessible_name]')
# 遍历元素并输出
for element in elements:
print(element.text)
# 关闭浏览器
driver.quit()
这段代码假设你已经安装了Selenium,并且使用了Chrome浏览器驱动。首先需要启动浏览器,然后打开你想要访问的网页。然后使用find_elements_by_css_selector方法找到所有符合条件的元素。CSS选择器.weui-desktop-icon__date[accessible_name]可以选择CLASS_NAME为'weui-desktop-icon__date'并且accessible_name属性不为空的元素。最后,通过遍历元素并输出它们的文本内容,你可以获取到这些元素的信息。最后,记得关闭浏览器以释放资源。
原文地址: https://www.cveoy.top/t/topic/pklK 著作权归作者所有。请勿转载和采集!