脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - 解决phantomjs截图失败,phantom.exit位置的问题

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

2021-02-21 00:42大杀风景 Python

今天小编就为大家分享一篇解决phantomjs截图失败,phantom.exit位置的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

刚刚学习使用phantomjs,根据网上帖子自己手动改了一个延时截图功能,发现延时功能就是不能执行,最后一点点排查出了问题。

看代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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位置的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/sunshine3257/article/details/70145728

延伸 · 阅读

精彩推荐