是的,你可以编写一个Lua脚本来做到这一点。像这样:
function main(splash)
splash:set_user_agent(splash.args.ua)
assert(splash:go(splash.args.url))
-- requires Splash 2.3
while not splash:select('.my-element') do
splash:wait(0.1)
end
return {html=splash:html()}
end
在Splash 2.3之前,你可以使用splash:evaljs('!document.querySelector(".my-element")')
代替not splash:select('.my-element')
。
将此脚本保存到变量(lua_script = """ ... """)
。然后,你可以发送如下请求:
yield SplashRequest(
url,
self.parse,
endpoint='execute',
args={
'lua_source': lua_script,
'ua': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"
}
}