其实url本质就是将中文字符串进行utf8编码
,然后得到编码后的对象转换字符串去掉开头的b'
以及末尾的'
,然后再将\x
转换成%
,再将里面内容x
变成e
最后将字符串小写
变成大写
举例
#拿我举例
#第一步进行编码
a= '我'
a= a.encode('utf8')
#第二步进行转字符串去除头尾
a = str(a).strip("b'") #strip里面的值不是匹配而是有无
#第三步将\转换成%
a = a.replace('\\','%')
#第四部将x写变成e
a = a.replace('x','e')
#第五步将小写变成大写
a = a.upper()
#一步到位
a=str(a.encode('utf8')).strip("b'").replace('\\x','%').replace('x','e').upper()
#结果%E6%88%91
#不行你可以访问 https://www.baidu.com/s?wd=%E6%88%91,https://www.baidu.com/s?wd=我
#看看是不是一样
from urllib import parse
str1 = '我'
str2 = parse.quote(str1)
print(str2)
#%E6%88%91
str1 = '%E6%88%91'
str2 = parse.unquote(str1)
print(str2)
#我
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有