url編碼本質
<iframe height="40" width="260" src="https://www.ximalaya.com/thirdparty/player/sound/player.html?id=305191879&type=red" frameborder="0" allowfullscreen=""></iframe>其實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=我
#看看是不是一樣
python中呼叫庫進行url編碼和解碼
from urllib import parse
編碼
str1 = '我'
str2 = parse.quote(str1)
print(str2)
#%E6%88%91
解碼
str1 = '%E6%88%91'
str2 = parse.unquote(str1)
print(str2)
#我
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/117291.html
標籤:Html/Css
上一篇:CSS animation屬性
