D
D
dhat2016-10-07 20:15:37
JavaScript
dhat, 2016-10-07 20:15:37

PhantomJS script not working, where is the error?

A simple script, I repeat everything as in the video - but it doesn't work.

var system = require('system');
var args = system.args;
var url = 'http://packtpub.com/';
var page = require('webpage');

// START
page.onError = function(msg, trace) {

  var msgStack = ['ERROR: ' + msg];

  if (trace && trace.length) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
    });
  }

  console.error(msgStack.join('\n'));

  phantom.exit(1);

};
// END

// handler for reciever resources
page.onResourceReceived = function(response) {
  console.log(response.contentType);
};

// react to any loaded page
page.onLoadFinished = function() {
  console.log('************');
  console.log('Page loaded');
  phanton.exit();
};

page.open( url );

Console writes:
TypeError: undefined is not a function (evaluating 'page.open( url )')

  phantomjs://code/network.js:37 in global code

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question