2017-02-23 54 views
0

我需要運行在飛濺這個簡單的Lua腳本:錯誤上飛濺的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選擇器字符串這個腳本工作?

回答

0

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