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

相关文章

Python input函数使用实例解析

这篇文章主要介绍了Python input函数使用实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 函数定义 def inpu...

python三方库之requests的快速上手

本文基于2.21.0 发送请求 发送GET请求: r = requests.get('https://api.github.com/events') 发送POST请求: r...

python 处理数字,把大于上限的数字置零实现方法

如下所示: # coding=utf-8 # 用来处理数字,大于上限的数字置零 f = open("/home/chuwei/桌面/trainA/loss/d_losses.tx...

Python判断变量是否已经定义的方法

Python判断变量是否已经定义是一个非常重要的功能,本文就来简述这一功能的实现方法。 其实Python中有很多方法可以实现判断一个变量是否已经定义了。这里就举出最常用的两种作为示例,如...

python中实现字符串翻转的方法

具体代码如下所示: #字符串反转 def reverse (s): rt = '' for i in range(len(s)-1,-1,-1): rt += s[i...