鱼C论坛

 找回密码
 立即注册
查看: 1449|回复: 4

[技术交流] Python Unicode 转 汉字

[复制链接]
发表于 2020-4-7 11:20:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 一个账号 于 2020-4-10 22:11 编辑
  1. def convert(content):
  2.     return content.encode("UTF-8").decode("Unicode_Escape")

  3. if __name__ == "__main__":
  4.     while True:
  5.         content = input("请输入 Unicode 代码:")
  6.         
  7.         target = convert(content)
  8.         
  9.         print(f"\n{target}\n")
复制代码

  1. from requests import post
  2. from bs4 import BeautifulSoup as bs


  3. def convert(content):
  4.     def find_data(res):
  5.         soup = bs(res.text, "html.parser")

  6.         target = soup.find("textarea", id="result")

  7.         return target.text

  8.     data = {}
  9.     data["content"] = content
  10.     data["untoch"] = "Unicode 转 中文"
  11.    
  12.     res = post("http://tool.chinaz.com/tools/unicode.aspx", data=data)
  13.     target = find_data(res)

  14.     return target

  15. if __name__ == "__main__":
  16.     while True:
  17.         content = input("请输入 Unicode 代码:")
  18.         
  19.         target = convert(content)
  20.         
  21.         print(f"\n{target}\n")
复制代码

  1. 请输入 Unicode 代码:\u5317\u4eac\u5e02

  2. 北京市
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-4-7 11:27:06 | 显示全部楼层
本帖最后由 永恒的蓝色梦想 于 2020-4-8 21:25 编辑
  1. while (temp:=input("请输入 Unicode 代码:")):
  2.     print(chr(int(temp,base=16)))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-10 21:22:46 | 显示全部楼层


转换的是 16 进制的 Unicode
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-10 21:24:38 | 显示全部楼层
一个账号 发表于 2020-4-10 21:22
转换的是 16 进制的 Unicode

给个输入输出示例
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-10 22:10:41 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-9 09:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表