Javascript 迭代增量时的幻影

Javascript 迭代增量时的幻影,javascript,while-loop,phantomjs,iteration,increment,Javascript,While Loop,Phantomjs,Iteration,Increment,我在迭代时遇到了一个问题,我必须增加纬度和打印图像的数量,以便使这个脚本自动使用phantomjs。当我启动控制台时,它不工作,它没有打印任何内容,可能我对迭代有错误,或者“phantom.exit”的位置有错误 有人能帮我吗?谢谢 n=0; l=10; while(l<22){ var page = require('webpage').create(); page.open("https://www.google.com/maps/preview/@11.483083,-"+l+

我在迭代时遇到了一个问题,我必须增加纬度和打印图像的数量,以便使这个脚本自动使用phantomjs。当我启动控制台时,它不工作,它没有打印任何内容,可能我对迭代有错误,或者“phantom.exit”的位置有错误 有人能帮我吗?谢谢

n=0;
l=10;  

while(l<22){
var page = require('webpage').create();
page.open("https://www.google.com/maps/preview/@11.483083,-"+l+".145460,10z/data=!3m1!1e3", function(status) {
page.viewportSize = { width: 1440, height: 900 };

page.clipRect = { top: 0, left: 0, width: 250, height: 250 };

  console.log("Status: " + status);
  if(status === "success") {
  n++;
  l++;
  phantom.exit();
    page.render('img-'+n+'.png');
  }
  }); 
};
n=0;
l=10;

虽然(l问题已经解决,但现在它正在工作:

var n=0,l=10;
function to_open(){
var page = require('webpage').create();
page.viewportSize = { width: 1440, height: 900 };
page.clipRect = { top: 0, left: 0, width: 250, height: 250 };
page.open("https://www.google.com/maps/preview/@11.483083,-"+l+".145460,10z/data=!3m1!1e3", function(status) {
  console.log("Status: " + status);
  if(status == "success") {
  n++;
  l++;
  page.render('img-'+n+'.png');
  if(n=="21") {setTimeout(phantom.exit,4000)}else{setTimeout(to_open,4000)}
}else{setTimeout(to_open,2000)}
  });
};to_open();