index.js
function scrape(url, model, options, cb) {

  /**
   * Make `options` argument optional
   */

  if ('function' === typeof options) {

    /**
     * Interchange `cb`'s position and fill `options` with nice defaults
     */

    cb = options;
    options = _.cloneDeep(DEFAULTS);

  } else {

    /**
     * Merge all options from `DEFAULTS` not present in `options`
     */

    _.defaultsDeep(options, DEFAULTS);

  }

  /**
   * Set `request`'s Uniform Resource Identifier to provied `url`
   * @type {string}
   */

  options.requestOptions.uri = url;

  /**
   * Call `request()` to get the resource
   */

  request(options.requestOptions, processResponse);

  /**
   * Handle `request()`'s result: Chain `err` or proceed to parse the resource.
   */

  function processResponse(err, res, body) {

    if (err) { return cb(err); }

    if (res.statusCode !== 200) {
      return cb(new ScrapeError('Not OK response from server.', res, body));
    }

    parseBody(body, model, options, cb);

  }
}
function scrape(url, model, options, cb) {

  /**
   * Make `options` argument optional
   */

  if ('function' === typeof options) {

    /**
     * Interchange `cb`'s position and fill `options` with nice defaults
     */

    cb = options;
    options = _.cloneDeep(DEFAULTS);

  } else {

    /**
     * Merge all options from `DEFAULTS` not present in `options`
     */

    _.defaultsDeep(options, DEFAULTS);

  }

  /**
   * Set `request`'s Uniform Resource Identifier to provied `url`
   * @type {string}
   */

  options.requestOptions.uri = url;

  /**
   * Call `request()` to get the resource
   */

  request(options.requestOptions, processResponse);

  /**
   * Handle `request()`'s result: Chain `err` or proceed to parse the resource.
   */

  function processResponse(err, res, body) {

    if (err) { return cb(err); }

    if (res.statusCode !== 200) {
      return cb(new ScrapeError('Not OK response from server.', res, body));
    }

    parseBody(body, model, options, cb);

  }
}
function scrape ( url , model , options , cb ) { /**
   * Make `options` argument optional
   */ if ( 'function' === typeof options ) { /**
     * Interchange `cb`'s position and fill `options` with nice defaults
     */ cb = options ; options = _ . cloneDeep ( DEFAULTS ) ; } else { /**
     * Merge all options from `DEFAULTS` not present in `options`
     */ _ . defaultsDeep ( options , DEFAULTS ) ; } /**
   * Set `request`'s Uniform Resource Identifier to provied `url`
   * @type {string}
   */ options . requestOptions . uri = url ; /**
   * Call `request()` to get the resource
   */ request ( options . requestOptions , processResponse ) ; /**
   * Handle `request()`'s result: Chain `err` or proceed to parse the resource.
   */ function processResponse ( err , res , body ) { if ( err ) { return cb ( err ) ; } if ( res . statusCode !== 200 ) { return cb ( new ScrapeError ( 'Not OK response from server.' , res , body ) ) ; } parseBody ( body , model , options , cb ) ; } }
Scrape a web page
@param  {string}           url           Valid URL to scrape
@param  {Object|string}    model         String or object describing the data to be extracted from the given url
@param  {Object}           [options={}]  Aditional options for request and cheerio
@param  {Function}         cb            Standard nodejs callback
@return {null}
Scrape a web page