scrapy:我可以从响应中提取请求表单数据吗?
scrapy: Can I extract request formdata from response?
我正在使用 scrapy 抓取一些数据,我想知道 Request 和 Response 存储了多少数据。
我的具体问题如下代码所示:
def parse(self,response):
r = FormRequest(url=url1, formdata={somedata}, callback=parse2)
#is this line necessary if I want the formdata being attached?
r.meta['formdata'] = formdata
yield r
def parse2(self,response):
#can I access to the formdata here without that line of code?
如有任何建议,我们将不胜感激。
是的,但是 formdata
已经转换为 body
,而且据我所知,它不是字典,而是一个字符串。
所以尝试 r.body
也快速提醒您可以通过以下方式检查对象的属性:
dir(r)
我正在使用 scrapy 抓取一些数据,我想知道 Request 和 Response 存储了多少数据。
我的具体问题如下代码所示:
def parse(self,response):
r = FormRequest(url=url1, formdata={somedata}, callback=parse2)
#is this line necessary if I want the formdata being attached?
r.meta['formdata'] = formdata
yield r
def parse2(self,response):
#can I access to the formdata here without that line of code?
如有任何建议,我们将不胜感激。
是的,但是 formdata
已经转换为 body
,而且据我所知,它不是字典,而是一个字符串。
所以尝试 r.body
也快速提醒您可以通过以下方式检查对象的属性:
dir(r)