Python3请求 - 使用表单数据发布请求 [英] Python3 request - Post request with Form Data
问题描述
我试图发送带有表单数据的POST请求到某种形式。我正在使用请求包。
$ p $
#!/ bin / python3.6
导入请求
FFF_search ='https ://www.fff.fr/la-vie-des-clubs/resultats'
data = {'address':75000}
session = requests.session()
r = session。 post(FFF_search,data = data,headers = {'User-Agent':'test'})
print(r.text)
这给了我找不到结果的结果页面。
也许我的问题更多的是关于我发送的数据。
这是POST请求,因为它必须在网站上完成(Chrome开发工具)。
您应该考虑几个问题: 您的
标题
字典无效。没有称为测试的用户 - Agnet。您应该只使用有效标题标题。尝试发送您在网络标签中看到的所有标题。 params
?
尝试发送像浏览器发送的确切请求(使用相同的参数和标题),并查看您收到的结果,同时关注上述问题。
I'm trying to send a POST Request with form data to some form. I'm using requests package.
#!/bin/python3.6
import requests
FFF_search = 'https://www.fff.fr/la-vie-des-clubs/resultats'
data = {'address':75000}
session = requests.session()
r = session.post(FFF_search, data=data, headers={'User-Agent':'test'})
print(r.text)
This gives me the result page where no result is found.
Maybe my problem is more about the data I'm sending. Here's the POST request as it must be done on the website (Chrome dev tools).
You should consider several issues:
Your's
headers
dict is not valid. There is no 'User-Agnet' that called test. You should use only valid headers headers. Try to send all the headers you see in the network tab.Your's data us clearly wrong. You should send the described Form Data ad a dictionary and pass it with
data=data
, as you do (but you do it with a wrong data). Maybe the data you are passing now is theparams
?
Try to send the exact request like your's browser sending (with the same params and headers), and see the results you are receiving, with paying attention to the issues above.
这篇关于Python3请求 - 使用表单数据发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!