Я использую ScrapyJS и выплеск для имитации отправки формы кнопку мышиScrapyJS - Как правильно подождать загрузки страницы?
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
После этого splash:runjs(js)
, я прибегая к пытался splash:wait(5)
splash:wait_for_resume
, чтобы получить результат. Это может не всегда работать (задержка сети), так есть ли лучший способ?
Довольно уверен, что всплеск позволяет ждать элемент быть видимым –
@PadraicCunningham Пожалуйста, проверьте мой выбор, пытался фурор: wait_for_resume (не уверен, если я делаю это правильно), но не повезло – Krishnaraj
не нашел подобный вопрос - https://github.com/scrapinghub/splash/issues/200 – Krishnaraj