Yes, you can write a Lua script for this. Something like that:
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
Prior to Splash 2.3, you can use splash:evaljs('!document.querySelector(".my-element")') instead of not splash:select('.my-element') .
Save this script to a variable ( lua_script = """... """ ). Then you can send a request like this:
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" } }
See the Scripting Tutorial and Reference for more information on how to write Splash Lua scripts.
source share