Giter Site home page Giter Site logo

phantom-server's Introduction

Phantom Server

This project uses the webserver library in PhantomJS to host a simple phantomjs webserver that will run scripts you pass it over http. This allows you to easily run scripts that require the DOM (d3, js enabled web scrapers) from NodeJS.

Example

This is a simple example demonstrating that window will be defined in your evaluate scripts. For a more complex example that uses d3, see examples/d3.

# script.js
/**
 * This is the function that will be run in the page by PhantomJS. It has access
 * anything you would normally have access to in a page.
 */
module.exports = function() {
    return window !== undefined;
};
# index.js
var path = require( 'path' );

var PhantomServer = require( 'phantom-server' ),
    phantomjs_path = require( 'phantomjs-prebuilt' ).path;

var phantom_server = new PhantomServer( phantomjs_path );

phantom_server
    .run( {
        evaluate_scripts: [
            path.join( __dirname, 'script.js' );
        ]
    } )
    .then( function( evaluate_responses ) {
        console.log( evaluate_responses[ 0 ] ); // true
        phantom_server.stop(); // MAKE SURE YOU STOP THE SERVER WHEN YOU ARE DONE
    } );

phantom-server's People

Contributors

frenchie4111 avatar

Stargazers

 avatar

Watchers

James Cloos avatar Kruk avatar  avatar Gregg Golembeski avatar  avatar  avatar day kay avatar Trini  avatar João Carvalho avatar  avatar

Forkers

gavinatork

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.