欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python对URL的编码和解码

程序员文章站 2024-02-14 22:59:52
...
@python
import urllib
#解码
print(urllib.parse.unquote('https%3A%2F%2Fapi.47ks.com%2Fconfig%2Fgetinfo.m3u8%3Fpt%3Dyouku%26src%3Dwebcloud%26t%3D1505203028%26vid%3DXMzAxOTE3ODg3Ng%253D%253D%26k%3D0a88ECxahNN79ehAnzl9DKKmUVRBM6Xo1oDZIn7UXMKOV359PKY5I9%252B6ikpS6w%26vf%3D2da28cbcaf8063a64b2fa414f8792700&c=0&p=1&s=4&v=100&lv=0&loaded=error'))

#输出
https://api.47ks.com/config/getinfo.m3u8?pt=youku&src=webcloud&t=1505203028&vid=XMzAxOTE3ODg3Ng%3D%3D&k=0a88ECxahNN79ehAnzl9DKKmUVRBM6Xo1oDZIn7UXMKOV359PKY5I9%2B6ikpS6w&vf=2da28cbcaf8063a64b2fa414f8792700&c=0&p=1&s=4&v=100&lv=0&loaded=error

#编码
print(urllib.parse.quote('https%3A%2F%2Fapi.47ks.com%2Fconfig%2Fgetinfo.m3u8%3Fpt%3Dyouku%26src%3Dwebcloud%26t%3D1505203028%26vid%3DXMzAxOTE3ODg3Ng%253D%253D%26k%3D0a88ECxahNN79ehAnzl9DKKmUVRBM6Xo1oDZIn7UXMKOV359PKY5I9%252B6ikpS6w%26vf%3D2da28cbcaf8063a64b2fa414f8792700&c=0&p=1&s=4&v=100&lv=0&loaded=error'))

#输出
https%253A%252F%252Fapi.47ks.com%252Fconfig%252Fgetinfo.m3u8%253Fpt%253Dyouku%2526src%253Dwebcloud%2526t%253D1505203028%2526vid%253DXMzAxOTE3ODg3Ng%25253D%25253D%2526k%253D0a88ECxahNN79ehAnzl9DKKmUVRBM6Xo1oDZIn7UXMKOV359PKY5I9%25252B6ikpS6w%2526vf%253D2da28cbcaf8063a64b2fa414f8792700%26c%3D0%26p%3D1%26s%3D4%26v%3D100%26lv%3D0%26loaded%3Derror