""" utf8 编码"""
from urllib.request import quote, unquote
url1 = "https://www.baidu.com/s?wd=百度"
# utf8编码,指定安全字符
ret1 = quote(url1, safe=";/?:@&=+$,", encoding="utf-8")
print(ret1)
"""gbk编码"""
from urllib.request import quote, unquote
url2 = "https://www.baidu.com/s?wd=百度"
ret2 = quote(url2, encoding="gbk")
print(ret2)
"""解码"""
from urllib.request import quote, unquote
url3 = 'https://www.baidu.com/s?wd=%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0'
ret3 = unquote(url3, encoding='utf-8')
print(ret3)
# https://www.baidu.com/s?wd=机器学习
https://www.cnblogs.com/nmydt/p/14493929.html