我仍在尝试找出为什么找不到和剥离这样的标记:
<!-- //-->。这些反斜杠会导致某些标签被忽略。
底层SGML解析器可能存在问题:请参阅http://www.crummy.com/software/BeautifulSoup/documentation.html#Sanitizing%20Bad%20Data%20with%20Regexps。您可以使用
markupMassage正则表达式来覆盖它-
直接来自文档:
import re, copymyMassage = [(re.compile('<!-([^-])'), lambda match: '<!--' + match.group(1))]myNewMassage = copy.copy(BeautifulSoup.MARKUP_MASSAGE)myNewMassage.extend(myMassage)BeautifulSoup(badString, markupMassage=myNewMassage)# Foo<!--This comment is malformed.-->Bar<br />Baz


