我相信使用“回调”方法是异步的,请纠正我,如果我错了。我对Python仍然很陌生,所以请耐心等待。如何在Scrapy上同步获取请求的Response对象?
无论如何,我试图让一个方法来检查文件是否存在,这里是我的代码:
def file_exists(self, url):
res = False;
response = Request(url, method='HEAD', dont_filter=True)
if response.status == 200:
res = True
return res
我想请求()方法会返回一个Response对象,但它仍然会返回一个Request对象,为了捕获Response,我必须为回调创建一个不同的方法。
有什么办法,你调用的响应()方法来获取代码块内的Response对象?
你可能想尝试https://github.com/rolando/scrapy-inline-requests –