以下是 PhantomJS 脚本的片段。它跟踪 AJAXd 网页上的动态内容。track() 被调用一次,但由于某种原因 page.open() 被调用了 3 次
function track(url){
console.log('Tracking',url);
var page = require('webpage').create();
console.log('check2')
if(page){
console.log('check4');
page.open(url, function (status) {
console.log('check3');
if (status !== 'success') {
console.log('Unable to load the address!');
setTimeout(function(){start();},1000);
setTimeout(function(){page.release();},5000);
}
else {
console.log('check');
var i = 0;
var last_winner = false;
var logged_once = false;
var interval = false;
if(!interval){
interval = setInterval(function(){
var scraping = scrape(page);
var date = new Date();
var time = date.getTime();
if(scraping){/*Bunch of console logs*/}
else{
console.log('Bidding ended');
clearInterval(interval);
setTimeout(function(){start();},1000);
setTimeout(function(){page.release();},5000);
}
scraping = false;
},1000);
};
};
});
};
};
将以下内容记录到控制台:
Tracking http://www.google.com
check2
check4
check3
check
check3
check
check3
check
出于某种原因,我无法弄清楚, page.open() 被调用了 3 次。