It seems like node-phantom is no longer maintained. This is a copy of that project with some fixes. The end result is published on npm as node-slimer.
node-slimer
This is a bridge between PhantomJs and Node.js.
It is very much similar to the other bridge available, PhantomJS-Node, but is different in a few ways:
- Way fewer dependencies/layers.
- API has the idiomatic error indicator as first parameter to callbacks.
- Uses plain Javascript instead of Coffeescript.
Requirements
You will need to install PhantomJS first. The bridge assumes that the "phantomjs" binary is available in the PATH.
The only other dependency for using it is socket.io.
For running the tests you will need Mocha. The tests require PhantomJS 1.6 or newer to pass.
Installing
npm install node-slimer
Usage
You can use it pretty much like you would use PhantomJS-Node, for example this is an adaptation of a web scraping example :
var phantom=;phantom;
phantom.create(callback,options)
options
is an optional object with options for how to start PhantomJS.
options.parameters
is an array of parameters that will be passed to PhantomJS on the commandline.
For example
phantom
will start phantom as:
phantomjs --ignore-ssl-errors=yes
You may also pass in a custom path if you need to select a specific instance of PhantomJS or it is not present in PATH environment. This can for example be used together with the PhantomJS package like so:
phantom
You can also use slimerJS:
phantom
Working with the API
Once you have the phantom instance you can use it much as you would the real PhantomJS, node-slimer tries to mimic the api.
An exception is that since this is a wrapper that does network communication to control PhantomJS, all methods are asynchronous and with a callback even when the PhantomJS version is synchronous.
Another notable exception is the page.evaluate method (and page.evaluateAsync method) that since PhantomJS 1.6 has a provision for extra arguments to be passed into the evaluated function. In the node-slimer world these arguments are placed after the callback. So the order is evaluatee, callback, optional arguments. In code it looks like :
page;
You can also have a look at the test folder to see some examples of using the API.
Other
Made by Alex Scheel Meyer. Released to the public domain.