简体   繁体   中英

Python encode string to html

How would one take a string and encode special characters to html?

for example, if I have "test@test" how would I encode it so it becomes "test%40test"

Is there an easy way of doing this instead of using replace to manually list every one I want to replace?

Try urlencode function. Documentation here.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM