类似这样使用!
req = scrapy.FormRequest('http://httpbin.org/post', formdata=data)
例子:
In [29]: req = scrapy.FormRequest('http://httpbin.org/post', formdata=data)
In [30]: fetch(req)
In [31]: response
Out[31]: <200 http://httpbin.org/post>
In [32]: print(response.body_as_unicode())
{
"args": {},
"data": "",
"files": {},
"form": {
"name": "python"
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "gzip,deflate",
"Accept-Language": "en",
"Connection": "close",
"Content-Length": "11",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Scrapy/1.4.0 (+http://scrapy.org)"
},
"json": null,
"origin": "112.96.195.12",
"url": "http://httpbin.org/post"
}
In [33]: r = requests.post('http://httpbin.org/post', data=data)
In [34]: print(r.text)
{
"args": {},
"data": "",
"files": {},
"form": {
"name": "python"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "11",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "112.96.195.12",
"url": "http://httpbin.org/post"
}