如何使用一些 lua 代码扩展 scrapy-splash 'render.html' 端点?

问题描述

所以,我想在 endpoint='execute' 中使用 scrapy-splash,但在我的 Lua 额外代码中模仿 endpoint='render.html'。但是我找不到应该如何完成的示例,以便将随请求发送的 Lua 代码与用于拦截带有所有参数的 HTML 的 Lua(我期望)相同。 有什么想法吗?

解决方法

据我所知,这不受支持,但我发现了这一点 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

重要提示:您必须将 --disable-lua-sandbox 添加到启动 (docker) 命令行