1dayitwillmake
1dayitwillmake

Reputation: 2339

Problems directly using PhantomJS in node.js

I'm attempting to use PhantomJS, and I've installed it via NPM. I can't seem to run any of the of the examples, in fact I can't even run:

var page = require('webpage').create();

I get the error:

Error: Cannot find module 'webpage'

Is there anything i'm missing? I'm using a few other modules that I've installed via NPM in the same directory with no issues

Upvotes: 26

Views: 16792

Answers (2)

Jeevan Kumar
Jeevan Kumar

Reputation: 1

You can use something like this:

var page = new WebPage();

Example of code :

var page = new WebPage();
page.open('http://example.com', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});

Upvotes: -1

Ariya Hidayat
Ariya Hidayat

Reputation: 12561

PhantomJS is not for Node.js. You are likely running the examples through node binary.

Read the Getting Started documentation carefully and you'll see that every single PhantomJS example need to be invoked like:

phantomjs hello.js

Note that there is a bridge between Node.js and PhantomJS. In that case, you need to follow the given examples for that particular bridge (there are a few different ones).

Upvotes: 53

Related Questions