url 编码
from urllib.parse import quote
from urllib.parse import urlencode
base_url = 'https://tieba.baidu.com/f?ie=utf-8&'
data = {
'kw': '美女'
}
print('https://s.taobao.com/search?q='+quote('美女'))
print(base_url+urlencode(data))
# 输出
https://tieba.baidu.com/f?ie=utf-8&kw=%E7%BE%8E%E5%A5%B3
https://tieba.baidu.com/f?ie=utf-8&kw=%E7%BE%8E%E5%A5%B3
quote 和 urlencode 的区别
urlencode 需要用字典
quote只需要用字符串
如上所述,多个参数的时候还是urlencode用得多一点
url 解码
from urllib import parse
print(parse.unquote("%40"))