Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (27 sloc) 974 Bytes

cheerful

the composition of Cheerio and hyperquestionable

Installation

$ npm install cheerful

API

var request$ = require('cheerful')

request$(url, function cb(err, $))

request url using hyperquestionable, run it through cheerio and hand it back to you. The HTTP status code is added to the Cheerio object and to Cheerio errors as statusCode.

Example:

var request$ = require('cheerful')
request$('http://google.com', findDoodle)
function findDoodle(err, $) {
  var headers = (err || $).headers
  if (headers && headers.location)
    return request$(headers.location, findDoodle)
  if (err) return console.error('error', err)

  var div = $('center div[title="Google"]')
  var img = 'http://google.com'+ div.attr('style').match(/url\((\S+)\)/)[1]
  console.log('today\'s Google Doodle:', img)
}

License

MIT

Jump to Line
Something went wrong with that request. Please try again.