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

yipeiwu_com6年前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判断windows隐藏文件的方法

python判断windows隐藏文件的方法

1. 通过windows attrib 命令获取文件隐藏属性复制代码 代码如下:Syntax      ATTRIB [ + attri...

python的dataframe转换为多维矩阵的方法

python的dataframe转换为多维矩阵的方法

最近有一个需求要把dataframe转换为多维矩阵,然后可以使用values来实现,下面记录一下代码,方便以后使用。 import pandas as pd import numpy...

Python version 2.7 required, which was not found in the registry

Python version 2.7 required, which was not found in the registry

安装PIL库的时候,直接提示:Python version 2.7 required, which was not found in the registry。 如图: 大意是说找不到...

Python中GeoJson和bokeh-1的使用讲解

Python中GeoJson和bokeh-1的使用讲解

GeoJson 文档 { "type": "FeatureCollection", "features": [ { "geometry": { "type":...

Python 返回汉字的汉语拼音

后来想到自己Delphi有一个获得拼音的代码。于是找了出来。研究了一下代码如下:复制代码 代码如下:function get_hz_pywb(hzstr: string; pytype:...