Scrapy-Splash如何将返回变量添加到响应

问题描述

我想运行一个启动脚本,该脚本在lua中执行一些操作,然后将这些结果返回给我的爬虫机器人。但是,我只能接收html正文,但是return语句中没有任何变量

splash:go(...)
--lua/splash stuff
test = 500
return {
-- another SO thread stated that these have to be in JSON format? doesn't work either way though
test = test
}

我尝试使用JSON端点,但是结果是相同的。 Scrapy-Splash文档也没有真正解释如何获取这些变量。

所以我的问题是-如何通过scrapy_plash.SplashRequest调用从lua脚本中接收任意返回变量?

这是我当前的启动请求:

yield SplashRequest(url,self.parse,args={'lua_source': Quotesspider.SPLASH_SCRIPT,'wait': 0.5})

解决方法

splashRequest的默认设置是render.html,它仅返回html而不执行lua脚本。正确添加执行端点将运行lua脚本,从而返回所需的变量

yield SplashRequest(url,self.parse,endpoint='execute'
    args={'lua_source': QuotesSpider.SPLASH_SCRIPT,'wait': 0.5})

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...