Skip to content

Instantly share code, notes, and snippets.

@andantonyan
Created October 20, 2015 11:58
Show Gist options
  • Save andantonyan/32a5ce2f042e16d1b862 to your computer and use it in GitHub Desktop.
Save andantonyan/32a5ce2f042e16d1b862 to your computer and use it in GitHub Desktop.
scraping with node
'use strict;'
var Q = require('q');
var fs = require('fs');
var writeFileQ = Q.nfbind(fs.writeFile);
var rp = require('request-promise');
var cheerio = require('cheerio');
var SCRAPING_URI = 'https://www.google.com/?q=cats';
var options = {
uri: SCRAPING_URI,
transform: function (body) {
return cheerio.load(body);
}
};
return rp(options)
.then(function ($) {
var json = {
title: $('title').text()
}
return writeFileQ('output.json', JSON.stringify(json, null, 2));
})
.then(function () {
process.exit(0);
})
.catch(function (err) {
console.log('Houston, we have a problem %s', err)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment