抓取一个慕课网修改头像的地址;
从上面抓包可以看出,没有data数据,是一个file
修改头像是登录成功之后才能操作的,所以在调用requests函数时需要传入cookies参数;
# 构建一个post请求
url = 'https://www.imooc.com/user/postpic'# 接口地址
#接口参数
# Content-Disposition: form-data; name="fileField"; filename="python.png"
# Content-Type: image/png
# Content-Disposition: form-data; name="type"
#fileField:("文件名称",open("路径","rb"),"image/png)
file = {
"fileField":("diaosi.png",open("./image/f00318249ac24e74986f717ae5720ebf.png",'rb'),"image/png"),
"type":"1"
}
cookie = {
"apsid":"U2Nzg2YzIyNDk5MjE1ZjQ0NWFkZjQ5NjJhNzY3MmIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTEwODYwODAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc5YTAxY2U4NzUyZmY1ZjI2OGE3M2MyMjlmYjdhNmEzzpzkYwAAAAA%3DOW"
}
res = requests.post(url,cookies=cookie,files=file,verify=False).text
print(res)