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

yipeiwu_com5年前Python基础

刚刚学习使用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设计】。

相关文章

完美解决python3.7 pip升级 拒绝访问问题

完美解决python3.7 pip升级 拒绝访问问题

python3.7 pip升级 拒绝访问 解决方案 pip install --upgrade pip --user ps:下面看下python中的for循环加强 #先执行外...

Python中的time模块与datetime模块用法总结

time模块 time模块是包含各方面对时间操作的函数. 尽管这些常常有效但不是所有方法在任意平台中有效. time用struct_time表示时间 import time # t...

python实现列表中由数值查到索引的方法

python实现列表中由数值查到索引的方法

如下所示: 以上这篇python实现列表中由数值查到索引的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。...

python中stdout输出不缓存的设置方法

考虑以下python程序:复制代码 代码如下:#!/usr/bin/env pythonimport syssys.stdout.write("stdout1 ")sys.stderr....

通过Python模块filecmp 对文件比较的实现方法

filecmp定义了两个函数,用于方便地比较文件与文件夹:     filecmp.cmp(f1, f2[, shallow]):  比较两个文件...