gpt4 book ai didi

python - 使用 beautifulsoup 获取跨度标题

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:08 25 4
gpt4 key购买 nike

我有这个跨度,我想得到标题

<span title="Something"></span>

如何用 beautifulsoup 得到它?

res = soup.find('span')
print res //Was trying to add res.title but result is 'None'

最佳答案

您应该能够像这样访问它:

res = soup.find('span')['title']

Docs

编辑:我应该澄清一下,res 将是 title 属性的值。如果您希望以后使用该元素,请将我的代码更改为:

res = soup.find('span')
title = res['title']

然后您可以继续使用 res(如果需要)。

此外,.find 将返回单个元素。您需要确保它是您想要的跨度,因为 HTML 可以有多个跨度。

关于python - 使用 beautifulsoup 获取跨度标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12982718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com