解决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设计】。

相关文章

浅谈Tensorflow由于版本问题出现的几种错误及解决方法

1、AttributeError: 'module' object has no attribute 'rnn_cell' S:将tf.nn.rnn_cell替换为tf.contrib....

python 构造三维全零数组的方法

如下所示: temp1 = [[] for i in range(10)] temp2 = [temp1 for i in range(20)] temp3 = [temp2 for...

将TensorFlow的模型网络导出为单个文件的方法

有时候,我们需要将TensorFlow的模型导出为单个文件(同时包含模型架构定义与权重),方便在其他地方使用(如在c++中部署网络)。利用tf.train.write_graph()默认...

详解numpy的argmax的具体使用

从最简单的例子出发 假定现在有一个数组a = [3, 1, 2, 4, 6, 1]现在要算数组a中最大数的索引是多少.这个问题对于刚学编程的同学就能解决.最直接的思路,先假定第0个数最大...

python jieba分词并统计词频后输出结果到Excel和txt文档方法

python jieba分词并统计词频后输出结果到Excel和txt文档方法

前两天,班上同学写论文,需要将很多篇论文题目按照中文的习惯分词并统计每个词出现的频率。 让我帮她实现这个功能,我在网上查了之后发现jieba这个库还挺不错的。 运行环境: 安装...