Javascript Casperjs随机延迟

Javascript Casperjs随机延迟,javascript,web-crawler,phantomjs,casperjs,Javascript,Web Crawler,Phantomjs,Casperjs,我使用casperjs,我想在rantom时间间隔内进入站点。 我编写了这样的代码,但不起作用: function getRandomIntFromRange(min, max) { return Math.round(Math.random() * (max - min)) + min; } var casper = require('casper').create(); casper.start('http://stackoverflow.com/'); casper.on('re

我使用casperjs,我想在rantom时间间隔内进入站点。 我编写了这样的代码,但不起作用:

function getRandomIntFromRange(min, max) {
  return Math.round(Math.random() * (max - min)) + min;
}


var casper = require('casper').create();
casper.start('http://stackoverflow.com/');

casper.on('remote.message', function(msg) {
  this.echo('remote message caught: ' + msg);
});

casper.then(function() { 
  for (i=0; i<=5; i++) { 
    delay = getRandomIntFromRange(1000, 5000);
    this.wait(delay, (
      function(j) { 
        return function() { 
          this.echo('Test ' + j + '; delay: ' + delay); 
        }; 
    })(i)); 
  } 
}); 

casper.run();
函数getRandomIntFromRange(最小值、最大值){ 返回Math.round(Math.random()*(max-min))+min; } var casper=require('casper').create(); 卡斯珀,开始http://stackoverflow.com/'); casper.on('remote.message',函数(msg){ this.echo('捕获的远程消息:'+msg); }); casper.then(函数(){ 对于(i=0;i
casper.then(function(){

对于(i=0;i你没有说什么不起作用。请通过编辑你的问题来澄清你的预期结果。
casper.then(function() { 
  for (i=0; i<=5; i++) { 
    delay = getRandomIntFromRange(1000, 5000);
    this.wait(delay, (
      function(j,d) { 
        return function() { 
          this.echo('Test ' + j + '; delay: ' + d); 
        }; 
    })(i,delay)); 
  } 
});