我有一个应用程序正在抓取数据的网站。它是在iFrame中抓取网站。我需要从相同的iframe中抓取后续网站,这两个网站都有一个条目地址,这个条目导致带有一个字段和一个按钮的页面。在该页面上,我在该字段中输入一个数字,然后按下按钮进入下一页。我遇到的问题是,当我(编码)按下按钮时,它不会等待页面加载并在有任何声音之前进行擦除。JS异步/加载行为
setTimeOut
和Delay
似乎完全被忽略。
$(document).ready(function() {
$('#startbutton').click(function() {
$('#iframe').attr('src', 'www.pageone.com');
// Here I start a load because I need to wait for the button to become available.
$('#iframe').one('load', function() {
$('#okbutton').click();
});
// This is where it goes wrong. I would assume that it waits for the second page
// to load. But it doesn't. Adding another load block didn't help.
scrapeFunction();
});
});
我该如何获得这些时机?
您是不是指'on'而不是'one'? – 2013-03-20 16:48:29
@VivinPaliath我假设他只希望它运行一次。 – Archer 2013-03-20 16:53:03
我的意思是一个,因为否则的话,负载继续点燃,并点击确定按钮:D – Difusio 2013-03-20 17:10:46