lapwinglabs / x-ray-phantom

phantom driver for x-ray.
112 stars 30 forks source link

rewrite complete. #4

Closed matthewmueller closed 9 years ago

matthewmueller commented 9 years ago

New phantom driver will be able to use all nightmare plugins and call out to nightmare in between plugins. Here are two examples:

var crawler = require('x-ray-crawler');
var driver = require('x-ray-phantom);

crawler('http://google.com')
  .driver(driver())
  .on('response', function($, ctx) {
    console.log(ctx.status);
  })
  .crawl(function(err) {
    if (err) throw err;
    console.log('done');
  })
var crawler = require('x-ray-crawler');
var driver = require('x-ray-phantom');

function phantom(ctx, nightmare, fn) {
  nightmare.goto(ctx.url)
  return fn(null, nightmare);
}

crawler('http://google.com')
  .driver(driver(phantom))
  .on('response', function($, ctx) {
    console.log(ctx.status);
  })
  .crawl(function(err) {
    if (err) throw err;
    console.log('done');
  })

Let me know your thoughts. Still need to update tests and readme.