phantomjs截图失败怎么办

这篇文章将为大家详细讲解有关phantomjs截图失败怎么办,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

刚刚学习使用phantomjs,根据网上帖子自己手动改了一个延时截图功能,发现延时功能就是不能执行,最后一点点排查出了问题。

看代码:

var page = require('webpage').create(), 
 system = require('system'), 
 address,file; 
 
if (system.args.length === 1) { 
 console.log('Usage: netlog.js <some URL>'); 
 phantom.exit(1); 
} else { 
 address = system.args[1]; 
 file = system.args[2]; 
 
 page.open(address, function (status) { 
  if (status == 'success') { 
   console.log('success file is ' + file); 
  } 
  window.setTimeout(function () 
   { 
   console.log('render ok'); 
   page.render(file); 
   phantom.exit();//<span >必须在settimeout里面调用结束语句</span> 
   },60*1000); 
   
 }); 
}

手动改的代码setTimeout里没有写phantom.exit(),而是放在setTimeout外面了,怎么都不能执行setTimeout里面的语句,放进去就ok了。。。

关于“phantomjs截图失败怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。