我想在每一页上捕捉一张截图。为了导航到不同的页面,有一个函数moveNext()。当我签入控制台时,我可以看到它按顺序导航到所有页面。然而,它不是同时在每一页截图,而是采取多个截图的最后一页。提供回调或等待选项吗?
casper.then(function () {
for (var currentPage = startPage; currentPage < lastPage; currentPage++) {
this.page.evaluate(function(currentPage) {
moveNext(currentPage);
}, currentPage);
phantomcss.screenshot('html', 'screenshot');
console.log(currentPage);
}
});发布于 2016-12-21 09:57:03
function captureScreenshot(width, height, device, startPage, lastPage) {
casper.viewport(width, height);
casper.then(function () {
var currentPage = startPage - 1;
/* Capture screenshot of footer */
phantomcss.screenshot('footer', 'footer');
/* Capture screenshot of header */
phantomcss.screenshot('header', 'header');
/* Capture main content screenshot */
casper.repeat(lastPage, function () {
this.page.evaluate(function (currentPage) {
moveNext(currentPage);
}, ++currentPage);
this.wait(8000, function () {
phantomcss.screenshot('#NavForm > .container', 'main-content');
});
});
});
}发布于 2016-12-06 05:24:18
for循环不能工作,因为它太快了。你可以使用这样的东西:
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
viewportSize:{width: 1600, height: 900}
});
var currentPage = 0,lastPage=5;
casper
.start()
.then(function to_call() {
if(currentPage<lastPage){
currentPage++;
/* this.page.evaluate(function(currentPage) {
moveNext(currentPage);
}, currentPage);
phantomcss.screenshot('html', 'screenshot');*/
this.echo("The currentPage number is: "+currentPage,"INFO");
this.wait(3000).then(to_call)
}
})
.run();https://stackoverflow.com/questions/40972740
复制相似问题