user1858027
user1858027

Reputation: 1007

How can I get the response from the Request in Scrapy?

Is there any way that I can get the response.body from the Request function in scrapy?

I have this:

request = Request("http://www.example.com",  callback = self.mytest)

def mytest(self, response)
     return response.body

Now I want to get response.body in a Python variable, How can I get that?

I want something like

myresponse = Request("http://www.example.com").get('response')

Upvotes: 6

Views: 5576

Answers (2)

Awais Asghar
Awais Asghar

Reputation: 39

try using the scrapy inline requests: https://github.com/rmax/scrapy-inline-requests/

Upvotes: 0

Steven Almeroth
Steven Almeroth

Reputation: 8192

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.

Upvotes: 4

Related Questions