簡體   English   中英

Splash Lua腳本上可能會出現錯誤

[英]Error expected near on Splash Lua Script

我需要在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選擇器字符串以使此腳本起作用?

我發現了基於另一個答案的答案,即使錯誤字符串不一樣。 使用scrapy + splash返回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
    """

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM