Last active
March 9, 2017 15:51
-
-
Save ryanburgess/01fc144b24d06321bfea to your computer and use it in GitHub Desktop.
An example using Cheerio to scrape HTML
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 cheerio = require('cheerio'); | |
var request = require('request'); | |
request({ | |
method: 'GET', | |
url: 'http://www.wordthink.com' | |
}, function(err, response, body, callback) { | |
if (err) return console.error(err); | |
$ = cheerio.load(body); | |
var post = $('#content .singlemeta:first-child .post'); | |
var word = post.find('.title').eq(0).text().replace('\r\n\t\t\t\t\t', '').replace('\r\n\t\t\t\t', ''); | |
var definition = post.find('p').eq(0).text().replace('\n', ''); | |
console.log(word); | |
console.log(definition); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it might be a better idea using
normalizeWhitespace: true
to remove\r\n\t