我有这样漂亮的代码多个URL,所有我想要做访问之间有些停顿,所以我添加了一个“的setInterval”,但这不工作:访问使用PhantomJS评估错误
var page = require('webpage').create();
// the urls to navigate to
var urls = [
'http://blogger.com/',
'https://github.com/',
'http://reddit.com/'
];
var i = 0;
// the recursion function
var genericCallback = setInterval(function() {
return function (status) {
console.log("URL: " + urls[i]);
console.log("Status: " + status);
// exit if there was a problem with the navigation
if (!status || status === 'fail') phantom.exit();
i++;
if (status === "success") {
//-- YOUR STUFF HERE ----------------------
// do your stuff here... I'm taking a picture of the page
page.render('example' + i + '.png');
//-----------------------------------------
if (i < urls.length) {
// navigate to the next url and the callback is this function (recursion)
page.open(urls[i], genericCallback());
} else {
// try navigate to the next url (it is undefined because it is the last element) so the callback is exit
page.open(urls[i], function() {
phantom.exit();
});
}
}
};
},2000);
// start from the first url
page.open(urls[i], genericCallback());
与截图错误我得到: 也许有人可以帮助我,并医治此代码?因为我对JS和PhantomJS都很陌生,所以任何帮助都会令人满意。 我从另一个计算器的答案在这里的代码 - Using Multiple page.open in Single Script 但
'状态'没有被定义....'page.open(url,callback(status));'...该作者给出的脚本通常是不正确的。 –
仍然是相同的错误=(它可能是别的吗? –
但我使用他的代码之前,它的工作现在我编辑setinterval - 它不工作,然后我做你说的所有,并得到相同的错误 –