TypeError:process_spider_output()为关键字参数'response'获取了多个值

时间:2015-06-26 06:52:44

标签: python scrapy

我有像这样的scrapy蜘蛛中间件类

class SaveSpiderMidlleWare:
    """ This is a middleware class which handles all the operations of  saving the spider response data into flat file """

    def  process_spider_output(response, result, spider):
        print("Response :",response.url)
        return response

哪个会返回此错误

TypeError: process_spider_output() got multiple values for keyword argument 'response'

触发抓取蜘蛛

1 个答案:

答案 0 :(得分:4)

def  process_spider_output(response, result, spider):

应该是

 def process_spider_output(self, response, result, spider):

这个方法是中间件对象的方法,python中的对象方法总是将对象引用作为第一个参数。 Docs for this method可能不包括self param,可能假设它的存在是显而易见的。