Python 将字符串编码为 html

Python encode string to html

如何获取字符串并将特殊字符编码为 html?

例如,如果我有 "test@test",我将如何对其进行编码,使其变为 "test%40test"

有没有一种简单的方法可以代替使用 replace 手动列出我要替换的每个对象?

尝试urlencode函数。文档在这里。

https://docs.python.org/2/library/urllib.html#urllib.urlencode