HTMLParser 有默认参数convert_charrefs,需要手工设成False,否则样例代码的 handle_entityref 方法不会起作用:
HTMLParser
convert_charrefs
False
handle_entityref
If convert_charrefs is True (the default), all character references (except the ones in script/style elements) are automatically converted to the corresponding Unicode characters. 摘自 Python 官方文档
If convert_charrefs is True (the default), all character references (except the ones in script/style elements) are automatically converted to the corresponding Unicode characters.
True
script
style
摘自 Python 官方文档
Sign in to make a reply
遥望君山
HTMLParser
有默认参数convert_charrefs
,需要手工设成False
,否则样例代码的handle_entityref
方法不会起作用: