在Python中转义HTML

时间:2009-08-08 15:38:18

标签: python html escaping

如何使用Python中的–等字符来转义HTML?

1 个答案:

答案 0 :(得分:2)

如果你有一个unicode字符串作为输入,你可以使用xmlcharrefreplace错误处理程序:

py> u"<p>\N{EN DASH}</p>".encode("ascii", "xmlcharrefreplace")
'<p>&#8211;</p>'