soooo
soooo

Reputation: 145

Take screenshot with PhantomJS from PHP and pass arguments to the script

I need to pass variable but not working

php

exec('phantomjs screenshot.js http://www.google.com google.png');

js

var args = require('system').args;
var page = require('webpage').create();
var address = system.args[1];
var image = system.args[2];

page.open(address , function () {
    page.render(image);
    phantom.exit();
});

if i run script without php i have

    phantomjs screenshot.js http://google.com google.com
0: screenshot.js
1: http://google.com
2: google.com
ReferenceError: Can't find variable: system

Upvotes: 0

Views: 690

Answers (1)

Vaviloff
Vaviloff

Reputation: 16856

Phantomjs can't find system variable because it is not defined.

You need to write either

var args = require('system').args;
var address = args[1];
var image = args[2];

or you could write

var system = require('system');
var address = system.args[1];
var image = system.args[2];

Upvotes: 1

Related Questions