I am using ScrapyJS and Splash to simulate a form submit button click
def start_requests(self):
script = """
function main(splash)
assert(splash:autoload("https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"))
assert(splash:go(splash.args.url))
local js = [[
var $j = jQuery.noConflict();
$j('#USER').val('frankcastle');
$j('#password').val('punisher');
$j('.button-oblong-orange.button-orange a').click();
]]
assert(splash:runjs(js))
local resumeJs = [[
function main(splash) {
var $j = jQuery.noConflict();
$j(document).ready(function(){
splash.resume();
})
}
]]
assert(splash:wait_for_resume(resumeJs))
return {
html = splash:html()
}
end
"""
splash_meta = {'splash': {'endpoint': 'execute', 'args': {'wait': 0.5, 'lua_source': script}}}
for url in self.start_urls:
yield scrapy.Request(url, self.after_login, meta=splash_meta)
def after_login(self, response):
print response.body
return
After doing splash:runjs(js)
, I am resorting to tried splash:wait(5)
splash:wait_for_resume
to get the result. This might not always work ( network latency ), so is there a better way?