import re
import HTMLParser
regexp = "&.+?;"
list_of_html = re.findall(regexp, page) #finds all html entites in page
for e in list_of_html:
h = HTMLParser.HTMLParser()
unescaped = h.unescape(e) #finds the unescaped value of the html entity
page = page.replace(e, unescaped) #replaces html entity with unescaped value
如果只想将HTML实体解析为其unicode等效实体:
对于python2.x,对于3.x,导入是
import html.parser
使用这个QandA和另一个QandA的提示,我有一个似乎有效的解决方案。它获取整个文档并从文档中删除所有html实体。在
相关问题 更多 >
编程相关推荐