Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active August 29, 2015 13:56
Show Gist options
  • Save Integralist/9001300 to your computer and use it in GitHub Desktop.
Save Integralist/9001300 to your computer and use it in GitHub Desktop.
{
"name": "WebScraping",
"main": "scrap.js",
"dependencies": {
"cheerio": "~0.13.1"
}
}
var http = require('http');
function download(url, callback) {
http.get(url, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
callback(data);
});
}).on('error', function() {
callback(null)
});
}
module.exports = download;
var cheerio = require('cheerio'); // converts string into dom tree and provides querying (and other) methods
var download = require('./scrap.js');
download('http://www.integralist.co.uk/', function(data) {
if (data) {
var $ = cheerio.load(data)
$('h2').each(function(index, item) {
console.log($(item).text());
});
}
else console.log('error');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment