问题描述
我想运行一个启动脚本,该脚本在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})