Created
December 14, 2016 18:31
-
-
Save kennylugo/35bcff85c5da39ec9e60c89296005dc9 to your computer and use it in GitHub Desktop.
Javascript crawler, aka scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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