代码之家  ›  专栏  ›  技术社区  ›  Milano

Lua脚本-错误的CSS选择器?“#选项卡导航主跨:包含(描述)”

  •  0
  • Milano  · 技术社区  · 7 年前

    我在用 Scrapy-splash 但这个问题是关于 Lua 剧本我需要等到一个元素出现。问题是这个元素只能使用文本进行导航。

    等效的XPATH是: //*[@id="tab-nav-main"]//span[text()="desc"]')

    我试过:

    #tab-nav-main span:contains(desc)
    

    在chrome中有效,但在 lua

    你会怎么做?

    function main(splash, args)
                splash:set_user_agent(args.ua)
                assert(splash:go(splash.args.url))
    
                local i=0
                local maxwait=5
    
                while not splash:select("#tab-nav-main span:contains(description)") do
                    if i==maxwait then
                        break     --times out at maxwait secs
                    end
                    i=i+1
                    splash:wait(1)      --each loop has duration 1sec
                end
                return {
                    html = splash:html(),
                    }
            end
    

    错误

    2019-03-14 17:07:05 [scrapy_splash.middleware] WARNING: Bad request to Splash: {'description': 'Error happened while executing Lua script', 'error': 400, 'info': {'splash_method': 'select', 'line_number': 9, 'error': 'cannot select the specified element {\'js_error\': \'Error: SyntaxError: DOM Exception 12\', \'js_error_type\': \'SyntaxError\', \'js_error_message\': \'SyntaxError: DOM Exception 12\', \'type\': \'JS_ERROR\', \'message\': "JS error: \'Error: SyntaxError: DOM Exception 12\'"}', 'source': '[string "..."]', 'message': '[string "..."]:9: cannot select the specified element {\'js_error\': \'Error: SyntaxError: DOM Exception 12\', \'js_error_type\': \'SyntaxError\', \'js_error_message\': \'SyntaxError: DOM Exception 12\', \'type\': \'JS_ERROR\', \'message\': "JS error: \'Error: SyntaxError: DOM Exception 12\'"}', 'type': 'SPLASH_LUA_ERROR'}, 'type': 'ScriptError'}
    
    0 回复  |  直到 7 年前