python post 请求求助
本帖最后由 Cool_Breeze 于 2021-6-17 17:27 编辑蓝色圈内数据怎么携带!
以下是本人代码!# -*- encoding = utf-8 -*-
import requests
import urllib.parse
header = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
}
form_data = {
"FileNo" : "44078",
"Description": "",
"WriteDate" : "",
"WriteDate1" : "2021-6-17",
"WriteBy" : "",
"submit" : "++"
}
form_data = urllib.parse.urlencode(form_data).encode('gb2312')
res = requests.post('xxx.asp', data = form_data, headers=header)
print(res.cookies.values())
with open('test.html', 'wb') as f:
f.write(res.content)
formdata这种字典就可以 不需要15行,会自动编码的 grekevin 发表于 2021-6-17 16:03
不需要15行,会自动编码的
好的,谢谢! 楼主你好萌 发表于 2021-6-17 16:01
formdata这种字典就可以
我的代码正确吗? 这个代码并没有把信息提交上去,网页是通过 inputtype="submit" 标签提交的! 不要转换,直接用字典就可以 # -*- encoding = utf-8 -*-
import requests
header = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
}
form_data = {
"FileNo" : "44078",
"Description": "",
"WriteDate" : "",
"WriteDate1" : "2021-6-17",
"WriteBy" : "",
"submit" : "++"
}
res = requests.post('xxx.asp', json= form_data, headers=header)
print(res.cookies.values())
with open('test.html', 'wb') as f:
f.write(res.content)
这样应该就可以了 VIP88888888 发表于 2021-6-17 17:25
# -*- encoding = utf-8 -*-
import requests
header = {
感谢回复,已经解决了! 代码没问题啊 那最后你是怎么解决的?
页:
[1]
2