2024-03-29 14:23:40 发布
网友
有没有办法把这个写在BeautifulSoup里?你知道吗
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"
如果要测试标记是否只有文本元素,可以尝试以下操作:
if hasattr(node, contents) and len(node.contents) == 1 and isinstance(node.contents[0], NavigableString): textLevelFlag = true else: something else
如果要测试标记是否只有文本元素,可以尝试以下操作:
相关问题 更多 >
编程相关推荐