Python处理HTML转义字符
hh= '<abc>'
import HTMLParser
html_parser = HTMLParser.HTMLParser()
txt = html_parser.unescape(hh) #这样就得到了txt = '<abc>'
print(txt)
import html
txt1 = html.escape(txt) # 这样又回到了 txt1 = '<abc>'
print(h)
hh = '<abc>'
import HTMLParser
import html
html_parser = HTMLParser.HTMLParser()
txt = html_parser.unescape(hh)
print(txt)
txt1 = html.escape(txt)
print(txt1)
注意:变量名不要和模块名重合,eg:变量名和模块名都为html。