Lua脚本 - 错误的CSS选择器?"#tab-nav-main span:contains(desc)"

我正在使用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]警告: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'}
点赞