urllib库 parse 之 urlencode编码
import urllib.parse
url='https://www.baidu.com/index'
name = 'xiaoming'
age = 18
sex = 'nan'
height = 180
data = {
'name':name,
'age':age,
'sex':sex,
'height':height,
}
#通过 urlencode函数 对参数进行处理,形成标准的url参数
qurey_string = urllib.parse.urlencode(data)
print(qurey_string) # 生成 name=xiaoming&age=18&sex=nan&height=180
#也可以自己写
# list = []
# for k,v in data.items():
# list.append(k + '=' + str(v))
# qurey_string = '&'.join(list)
# print(qurey_string) # 生成 name=xiaoming&age=18&sex=nan&height=180
url = url+'?'+qurey_string
print(url) # https://www.baidu.com/index?name=xiaoming&age=18&sex=nan&height=180