Skip to content

Instantly share code, notes, and snippets.

@waltir
Last active Apr 30, 2019
Embed
What would you like to do?
Cheerio.js Setup
require('events').EventEmitter.defaultMaxListeners = 100;
const cheerio = require('cheerio');
const request = require('request');
request({
method: 'GET',
url: 'https://www.npr.org/sections/national/'
}, (err, res, body) => {
if (err) return console.error(err);
let $ = cheerio.load(body);
let title = $('title').text();
console.log(title); // Log the page title to the terminal
// Iterate over each of the posts on the page and log the url to the terminal
$('div.imagewrap > a').each(function(index, elem) {
let link = $(elem).attr('href');
console.log(link)
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment