print u'<'
我怎样才能打印<
print '>'
我怎样才能打印>
你应该使用HTMLParser
模块到解码html https://stackoverflow.com/questions/663058/html-entity-codes-to-text:
>>> import HTMLParser
>>> h= HTMLParser.HTMLParser()
>>> h.unescape('alpha < β')
u'alpha < \u03b2'
为了转义 HTML,cgi模块没问题 https://stackoverflow.com/questions/1061697/whats-the-easiest-way-to-escape-html-in-python:
>>> cgi.escape(u'<a>bá</a>').encode('ascii', 'xmlcharrefreplace')
'<a>bá</a>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)