stableboy

 

(转)网址链接中的中文编码

 

https://blog.csdn.net/mouday/article/details/80278938

 

可以利用百度进行URL编码解码 默认gbk

https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD

 

中文的gbk(GB2312)编码: 一个汉字对应两组%xx,即%xx%xx
中文的UTF-8编码: 一个汉字对应三组%xx,即%xx%xx%xx
可以利用百度进行URL编码解码 默认gbk

https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD
1
python3编码解码示例
# -*- coding: utf-8 -*-

# @File : urldecode_demo.py
# @Date : 2018-05-11

from urllib.request import quote, unquote

# 编码

url1 = "https://www.baidu.com/s?wd=中国"

# utf8编码,指定安全字符
ret1 = quote(url1, safe=";/?:@&=+$,", encoding="utf-8")
print(ret1)
# https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD

# gbk编码
ret2 = quote(url1, encoding="gbk")
print(ret2)
# https%3A//www.baidu.com/s%3Fwd%3D%D6%D0%B9%FA


# 解码
url3 = "https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD"

ret3 = unquote(url3, encoding='utf-8')
print(ret3)
# https://www.baidu.com/s?wd=中国
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
参考:
Python进行URL解码
————————————————
版权声明:本文为CSDN博主「彭世瑜」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mouday/article/details/80278938

 

posted on 2021-12-28 01:07  陌翔  阅读(1063)  评论(0编辑  收藏  举报

导航