phantom-fetch

A wrapper for PhantomJS for simple data fetching

npm install phantom-fetch
8 downloads in the last month

phantom-fetch

'phantom-fetch' is a wrapper for PhantomJS for simple data fetching from the web.

Installation

To install, type

npm install phantom-fetch

or add it to your package.json as a dependency.

Usage

require phantom-fetch:

var fetcher = require('phantom-fetch');

Set the polling function that will be run on the site:

function pollingFunction() {
  return document.querySelector('title').innerHTML;
}

The polling function should return a falsy value while the wanted value is not available.

Set a callback for when the wanted value is returned, or when the timeout is reached:

function callback(err, id, result, exit) {
  console.log(result);
  exit();
}

And initiate the fetcher:

fetcher.fetch({
  id: 1,
  url: "http://github.com",
  pollingFunction: pollingFunction,
  callback: callback
});

Also, options could be set with:

fetcher.options({
  verbose: true, //def false
  interval: 500, //def 100
  timeout: 4000 //def 10000
});

For more examples, see here

Issues

If you are having any problems, requests or criticism, don't hesitate to open an issue, here

npm loves you