如何从 Scrapy 中的请求获得响应? [英] How can I get the response from the Request in Scrapy?
本文介绍了如何从 Scrapy 中的请求获得响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法可以从scrapy的Request函数中获取response.body
?
Is there any way that I can get the response.body
from the Request function in scrapy?
我有这个:
request = Request("http://www.example.com", callback = self.mytest)
def mytest(self, response)
return response.body
现在我想在 Python 变量中获取 response.body
,我该如何获取?
Now I want to get response.body
in a Python variable, How can I get that?
我想要类似的东西
myresponse = Request("http://www.example.com").get('response')
推荐答案
有没有办法从刚创建的 Request 中获取 Response? 没有,只有回调函数可以访问 Response.进入回调后,您可以通过 response.request 访问请求,但反之则不行.
Is there a way to get the Response from a Request you just created? No, only the callback function has access to the Response. Once inside the callback you can access the Request via response.request, but not vise-versa.
这篇关于如何从 Scrapy 中的请求获得响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文