url encoded nature

In fact, the essence is the Chinese url string utf8编码, and then get the object code conversion after the beginning of removing the string b'and the end ', and then \xconvert %, and then inside the content xbecomes efinal string will 小写become大写

For example

#拿我举例

#第一步进行编码
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=我
#看看是不是一样

Guess you like

Origin www.cnblogs.com/pythonywy/p/11696583.html