标签: python html escaping
如何使用Python中的–等字符来转义HTML?
–
答案 0 :(得分:2)
如果你有一个unicode字符串作为输入,你可以使用xmlcharrefreplace错误处理程序:
py> u"<p>\N{EN DASH}</p>".encode("ascii", "xmlcharrefreplace") '<p>–</p>'