我将列表与Tag和NavigableString Type混合在一起。我想只访问Tag数据。我怎么检查?我想避免以下错误。
AttributeError: type object 'BeautifulSoup' has no attribute 'NavigableString'
答案 0 :(得分:3)
from bs4 import Tag, NavigableString, BeautifulSoup
html = r"<b>The Dormouse's story</b>"
soup = BeautifulSoup(html, 'lxml')
print(isinstance(soup, Tag))
print(isinstance(soup.string, NavigableString))
出:
True
True