剛剛學習使用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位置的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答