首页 > 解决方案 > 回调返回 NameError - Scrapy

问题描述

在最后一个名为last的方法中使用回调时遇到问题。我收到以下错误

NameError: name 'last' is not defined 

上面的一种方法绝对可以正常工作,即使它使用相同的逻辑。如果有人有任何想法,我将不胜感激。

编辑:我试过放 self.last 但我遇到了同样的问题——这次 self 没有定义。

谢谢!

在此处输入图像描述

标签: pythonscrapy

解决方案


除了将回调参数配置为 with self.last
蜘蛛方法应该有严格的selfresponse作为方法参数(不是regionregion_2)。否则SplashRequest将无法识别callback功能

   ....
        def third(self, response): #not def third(region, response)
    ........
            yield SplashRequest(region_2, callback=self.last,....


        def last(self, response): #not def third(region, response)

推荐阅读