javascript - Why do my phantomjs script output no screenshot (command line args version) -


i modified basic phantomjs example here http://phantomjs.org/screen-capture.html accept command line args.

when pass http://google.com argument console.log outputs correct

0: index.js

1: http://google.com

but don't thumbnail.png in folder why ?

    var page = require('webpage').create();      var system = require('system');     var args = system.args;      var url;      if (args.length === 1) {       url = 'http://github.com/';     } else {       args.foreach(function(arg, i) {         console.log(i + ': ' + arg);          if (i > 0) {           page.open(arg, function() {                page.render('thumbnail' + '.png');             });         }        });     }      phantom.exit(); 

page.open asynchronous function, therefore phantom.exit being called before callback render thumbnail.

move phantom.exit inside callback specified in docs

var page = require('webpage').create();   page.open('http://github.com/', function() {   page.render('github.png');   phantom.exit(); }); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -