python - 回调返回 NameError - Scrapy
问题描述
在最后一个名为last的方法中使用回调时遇到问题。我收到以下错误
NameError: name 'last' is not defined
上面的一种方法绝对可以正常工作,即使它使用相同的逻辑。如果有人有任何想法,我将不胜感激。
编辑:我试过放 self.last 但我遇到了同样的问题——这次 self 没有定义。
谢谢!
解决方案
除了将回调参数配置为 with self.last
。
蜘蛛方法应该有严格的self
和response
作为方法参数(不是region
和region_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)
推荐阅读
- transactions - 如何回滚 asyncpg 事务
- flutter - Flutter 错误尝试将名称更正为现有方法的名称,或定义名为“ancestorStateOfType”的方法
- android-jetpack-compose - 可变形的东西?
- javascript - Vue3js路由器链接到带有基于标头的偏移值的散列
- r - 极坐标ggplot图中两条线之间的阴影区域
- python - Python 2D 数组在行和列上搜索相邻单元格元素
- reactjs - 当我尝试在终端中运行 npm 时,它显示错误
- python - 字符串列表中的匹配日期返回空列表
- javascript - 有没有办法用 Javascript 修改 URL?
- react-native - 为什么 ListItem 内容没有显示任何内容