直接写了个api接口,用requests库可以成功的POST数据,但是一用scrapy.FormRequests去POST数据,数据都是空的。
class LpPipeline(object):
def process_item(self, item, spider):
post_url = 'http://www.xxxxxxxxx.com/videos_api'
post_data = {
"title": item['title'],
"img": img_url,
"content": item['content']
}
return [FormRequest(url=post_url, formdata=post_data, method='POST')]
不知道错误在哪?有人知道吗?
谢谢。
为什么在
Pipeline
里?这里的请求是不会发出去的,你只有在spider
的回调函数里构造并返回Request
或者FormRequest
,这个请求才会被调度、下载、并返回响应。