【问题标题】:Error expected near on Splash Lua ScriptSplash Lua 脚本附近预期错误
【发布时间】:2017-07-14 15:48:20
【问题描述】:

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

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

        -- go back 1 month in time and wait a little (1 second)
        assert(splash:runjs("$('a[data-ci-test-id=\"checkOutButton\"]').click()"))
        assert(splash:wait(1))

        -- return result as a JSON object
        return {
            html = splash:html(),
            -- we don't need screenshot or network activity
            --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'Error happened while executing Lua script', u'error': 400}

我应该如何编写 CSS 选择器字符串才能使该脚本正常工作?

【问题讨论】:

    标签: python lua syntax-error scrapy-splash splash-js-render


    【解决方案1】:

    即使错误字符串不相同,我也根据另一个答案找到了答案。 Use scrapy + splash return html

    原来,我抓取的页面没有JQuery,所以我必须先加载JQuery包。

        script = """
        function main(splash)
            # add this vvv
            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))
    
            -- go back 1 month in time and wait a little (1 second)
            assert(splash:runjs("$('div.minicart_summery > a.btn_checkout').click()"))
            assert(splash:wait(1))
    
            -- return result as a JSON object
            return {
                html = splash:html(),
                -- we don't need screenshot or network activity
                --png = splash:png(),
                --har = splash:har(),
            }
        end
        """
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      • 2014-06-03
      • 1970-01-01
      • 2016-06-27
      相关资源
      最近更新 更多