python中的URL编码和解码:
test.py
# 引入urllib的request模块
import urllib.request url = 'https://www.douban.com/j/search?q=刘德华&start=20&cat=1002'
print('原来的url为: ' + url)
# url编码 safe ='/:?=&' 表示/:?=&不转义
url_encode = urllib.request.quote(url, safe='/:?=&', encoding='utf-8')
print('输出编码后的url_encode: '+ url_encode)
# url解码
url_decode = urllib.request.unquote(url_encode)
print('输出解码后的url_decode: '+ url_decode)
运行后: