Skip to content

Instantly share code, notes, and snippets.

@kennylugo
Created December 14, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennylugo/35bcff85c5da39ec9e60c89296005dc9 to your computer and use it in GitHub Desktop.
Save kennylugo/35bcff85c5da39ec9e60c89296005dc9 to your computer and use it in GitHub Desktop.
Javascript crawler, aka scraper
var request = require('request');
var cheerio = require('cheerio');
request('http://www.factmonster.com/countries.html', function(error, response, html){
if(!error && response.statusCode == 200){
var $ = cheerio.load(html);
$('td').each(function(i, element){
// var a = $(this).prev();
var title = $("tr td a").text();
var metadata = {
title: title
};
console.log(metadata);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment