加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

解决phantomjs截图失败,phantom.exit位置的问题

发布时间:2020-12-16 21:13:21 所属栏目:Python 来源:网络整理
导读:刚刚学习使用phantomjs,根据网上帖子自己手动改了一个延时截图功能,发现延时功能就是不能执行,最后一点点排查出了问题。 看代码: var page = require('webpage').create(),system = require('system'),address,file; if (system.args.length === 1) { co

刚刚学习使用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 style="color:#ff0000;">必须在settimeout里面调用结束语句</span> 
   },60*1000); 
   
 }); 
} 

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

以上这篇解决phantomjs截图失败,phantom.exit位置的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。

您可能感兴趣的文章:

  • Python使用Phantomjs截屏网页的方法

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读