Beautiful Soup 如何提取类属性值?

我用beautifulsoup提取class的多个属性值,但['fa', 'fa-address-book-o']不是我想要的结果。


from bs4 import BeautifulSoup


html = "<i class='fa fa-address-book-o' aria-hidden='true'></i>"


soup = BeautifulSoup(html, "lxml")


h2 = soup.select("i")


print(h2[0]['class'])

我希望效果如下:


fa fa-address-book-o


慕运维8079593
浏览 242回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python