Modules

Below are listed all the installed modules that you can require() within your scripts. All modules are installed directly from NPM.

If you need us to install a specific module, contact us at contact@phantombuster.com and we’ll do what we can.

To know the exact installed version of each module and the different versions of PhantomJS available, please see Packages.

For CasperJS, PhantomJS or Node

These modules are compatible with all the Phantombuster commands (CasperJS, PhantomJS and Node). Require them at will.

  • phantombuster — Access Phantombuster’s services (download and save files, send emails, ...)
  • async — Higher-order functions and common patterns for asynchronous code
  • bluebird — Full featured Promises/A+ implementation
  • deep-diff — Calculate object differences
  • jstoxml, jsontoxml, easyxml, data2xml — Convert objects or JSON to XML
  • linq — Microsoft’s Language Integrated Query (LINQ) for JavaScript
  • mime — Mime-type mapping
  • pretty-data2, pretty-data — Pretty-print or minify XML, JSON, CSS and SQL files
  • resemblejs — Image analysis and comparison with HTML5
  • underscore — Functional programming helper library
  • xmltojson — Convert XML to objects or JSON

For CasperJS and PhantomJS only

These modules are only compatible with CasperJS or PhantomJS.

For Node only

These modules are only compatible with Node.

Other modules

These modules are also available and compatible with Node. However, we have not yet tested them for CasperJS or PhantomJS compatibility.

  • axios — Promise based HTTP client
  • babel-polyfill — ES2015 environment emulation
  • cheerio — Implementation of core jQuery for the server
  • es6-promise — Tools for organizing asynchronous code (ES6 Promise polyfill)
  • is-my-json-valid, jsen — JSON Schema validation
  • jsdom — Implementation of the DOM and HTML standards
  • lodash — JavaScript utility library
  • moment — Parse, validate, manipulate, and display dates
  • once — Only call a function once
  • pluralize — Pluralize and singularize any word
  • q — Library for promises (CommonJS/Promises/A,B,D)
  • qs — Querystring parser
  • when — Lightweight Promises/A+ and when() implementation

Injectable modules

These modules come preloaded on all agent disks. They can be injected in visited pages for easier DOM manipulation (mainly for scraping and automation purposes).

Use nick.inject() or page.injectJs() from PhantomJS to add them in web pages.

  • ../injectables/jquery-2.2.3.min.js - jQuery 2 (84kB)
  • ../injectables/jquery-3.0.0.min.js - jQuery 3 (85kB)
  • ../injectables/underscore-1.8.3.min.js - Underscore (17kB)
  • ../injectables/lodash-core-4.13.1.min.js - Lodash (core build, 12kB)
  • ../injectables/lodash-full-4.13.1.min.js - Lodash (full build, 67kB)

For example, to use jQuery in a page that doesn’t include it already, you could do this:

nick.inject('../injectables/jquery-3.0.0.min.js', function(err) {
    if (!err)
        console.log('jQuery injected in current page')
});

Writing your own modules

When the name of a script starts with lib, its launch will be disabled. This allows you to safely write reusable modules that can later be required using phantombuster dependencies and then require().

To create a new module, log in, go to your scripts page, select the reusable module tab and enter your module name.

// In script "lib-Foo.js"
"use strict";

module.exports = {
    foo: function() {
        console.log("bar");
    }
}
// In script "my-script.js"

"use strict";
"phantombuster command: casperjs";
"phantombuster package: 2";
"phantombuster dependencies: lib-Foo.js";

require("lib-Foo").foo(); // outputs "bar"

Please note that there is no need to specify your script extension when you require it. Both JavaScript and CoffeeScript modules can be required without their extensions.

There are a few more subtleties to consider when writing your own modules:

  • If you write a CoffeeScript module and want to require it from a JavaScript script using Phantombuster package 1, you will need to add this require('coffee-script/register') to the requiring script. Package 2+ scripts do not need this because in this case CoffeeScript is transpiled to JavaScript before the bot is started.
  • If you want to use CasperJS internal modules in your own module, you will need to add this require = patchRequire(require);. Obviously the requiring script must be started with the casperjs command in this case. More info here