简体   繁体   English

如何使用Python将简体中文字符转换为html转义字符?

[英]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.

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