如何扩展scrapy-splash的'render.html'端点以添加一些Lua代码?

所以,我想使用scrapy-splash,'endpoint='execute'',但是用Lua额外的代码模拟'endpoint='render.html''。但我找不到一个示例,如何做到Lua代码将与请求一起发送,与拦截HTML及其所有参数中使用的Lua(我期望的)相同。 有什么想法吗?

点赞
用户4226806
用户4226806

据我所见,目前不支持此功能,但我找到了这个 https://github.com/scrapinghub/splash/blob/master/splash/tests/lua_modules/emulation.lua 脚本,它模仿了实际运行 render.html(和其他端点)的 Python 代码。

这将允许尽可能地模拟运行 render.html 的 Python 代码,并且应该很容易用 lua / js 代码扩展。

注意:您需要在 emulation.lua 的底部添加以下行:

function main(splash)
  return {
    html = emulation.render_html(splash)
  }
end

重要提示:您必须在 splash(docker)命令行中添加 --disable-lua-sandbox

2021-07-22 20:50:18