如何收到刮擦的回应.请求() 在调用它的同一个函数中?



我对 Scrapy很陌生,并且有这个要求,我需要将 Scrapy 请求的响应返回到调用它的函数。 目前,我通过使用抓取内联请求库仅找到了 1 个解决方案

在Scrapy中有什么本地方法吗?

例如

def parse(self, response):
item = spiderItem()
# Extract some items here from this response using CSS Selectors
# ....
# ....
# Now extract URL from the response
new_url = response.css("div.urls::text").get()
yield scrapy.Request(new_url, callback=self.parse_more)
# Receive the response from parse_more() here. Is it possible?
resp = 
def parse_more(self, response):
# This function should be able to return the response back to the parse() function for further processing.

类似于我们在请求库中能够做的事情

response = requests.get(url)

由于 Scrapy 是建立在 Twisted 异步库之上的,所以不要认为这是不可能的。使用 HTTP 响应调用回调方法,而不会阻塞调用线程。

最新更新