我有以下
<h3>The price of something is <span title="60,487">60.5k</span></h3>
我想从跨度中获得标题。这是如何完成的?此跨度标题是动态的,并且会从网站更改。
答案 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'