Cheerio.js Setup
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
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