使用BeautifulsSoup隔离跨度标题

时间:2017-06-08 18:23:41

标签: python beautifulsoup

我有以下

<h3>The price of something is <span title="60,487">60.5k</span></h3>

我想从跨度中获得标题。这是如何完成的?此跨度标题是动态的,并且会从网站更改。

1 个答案:

答案 0 :(得分:0)

您可以使用CSS selectors.

执行此操作
>>> from bs4 import BeautifulSoup as BS
>>> html = """<h3>The price of something is <span title="60,487">60.5k</span></h3>"""
>>> soup = BS(html, "html.parser")
>>> soup.select_one("h3 > span[title]").get("title")
'60,487'