[英]How to convert Simplified Chinese characters to html escape characters with Python?
I want to get the html escape characters from Simplified Chinese (GB18030). 我想从简体中文(GB18030)中获取html转义字符。
I tried using the Python library html.escape
but it does not work. 我尝试使用Python库
html.escape
但它不起作用。
For example, 宁波
to %C4%FE%B2%A8
and 江北
to %BD%AD%B1%B1
. 例如,
宁波
到%C4%FE%B2%A8
, 江北
到%BD%AD%B1%B1
。
How to solve this problem? 如何解决这个问题呢?
Thank you. 谢谢。
import urllib
urllib.parse.quote('宁波', encoding='GB18030') == '%C4%FE%B2%A8'#True
urllib.parse.quote('江北', encoding='GB18030') == '%BD%AD%B1%B1'#True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.