You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python和Selenium获取span标签的title属性值

你已经通过XPath定位到了目标span元素,直接调用Selenium WebElement对象的get_attribute()方法,传入属性名title即可获取对应属性值:

followers_button = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span')
# 获取title属性值
title_content = followers_button.get_attribute('title')
# 打印查看结果
print(title_content)

补充说明:get_attribute()是Selenium中获取元素属性的通用方法,不管是标准属性(比如title、href、class)还是自定义的元素属性,都可以通过传入属性名称的方式拿到对应值。


内容的提问来源于stack exchange,提问作者Дмитрий Гуща

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 05:54:03