Splash Lua脚本上期望的错误

我需要在Splash上运行这个简单的Lua脚本:

    script = """
    function main(splash)
        local url = splash.args.url
        assert(splash:go(url))
        assert(splash:wait(1))

        -- 回溯一月时间并等待一段时间(1秒)
        assert(splash:runjs("$('a[data-ci-test-id=\"checkOutButton\"]').click()"))
        assert(splash:wait(1))

        -- 将结果作为JSON对象返回
        return {
            html = splash:html(),
            -- 我们不需要屏幕截图或网络活动
            --png = splash:png(),
            --har = splash:har(),
        }
    end
    """

但我得到了以下错误:

{u'info': {u'source': u'[string "..."]', u'message': u'[string "..."]:8: \')\' expected near \'checkOutButton\'', u'line_number': 8, u'type': u'LUA_INIT_ERROR', u'error': u"')' expected near 'checkOutButton'"}, u'type': u'ScriptError', u'description': u'执行Lua脚本时发生错误', u'error': 400}

如何编写这个脚本的CSS选择器字符串才能使它工作?

点赞
用户1564659
用户1564659

尽管错误字符串不同,但我根据另一个答案找到了答案。

使用 Scrapy + Splash 返回 HTML

事实证明,我爬取的页面没有 JQuery,所以我必须先加载 JQuery 包。

    script = """
    function main(splash)
        # 添加这一行
        assert(splash:autoload("https://code.jquery.com/jquery-3.1.1.min.js"))
        local url = splash.args.url
        assert(splash:go(url))
        assert(splash:wait(1))

        -- 回到一个月前并稍微等一下(1 秒钟)
        assert(splash:runjs("$('div.minicart_summery > a.btn_checkout').click()"))
        assert(splash:wait(1))

        -- 将结果作为 JSON 对象返回
        return {
            html = splash:html(),
            -- 我们不需要截图或网络活动
            --png = splash:png(),
            --har = splash:har(),
        }
    end
    """

2017-02-23 23:58:30