有没有办法用BeautifulSoup写这段代码?
for node in soup:
if node is in ["a", "b", "i", ...]: # node is tag of type `a` or `b` ...
# we are probably on the text level
textLevelFlag = true
else:
# "we are higher"发布于 2011-11-21 20:20:14
如果你想测试你的标签是否只有文本元素,你可以尝试这样做:
if hasattr(node, contents) and len(node.contents) == 1 and isinstance(node.contents[0], NavigableString):
textLevelFlag = true
else:
something elsehttps://stackoverflow.com/questions/8204349
复制相似问题