0

すべてのページでスクリーンショットをキャプチャしたいと思います。別のページに移動するには、関数がありますmoveNext()。コンソールを確認すると、すべてのページに順番に移動していることがわかります。ただし、すべてのページで同時にスクリーンショットを撮るのではなく、最後のページの複数のスクリーンショットを撮ります。casperjs はコールバックまたは待機オプションを提供しますか?

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);
            }
        });
4

2 に答える 2

0

速すぎるため、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();
于 2016-12-06T05:24:18.200 に答える