Skip to content

Instantly share code, notes, and snippets.

@DanNi0130
Created July 19, 2018 01:35
Show Gist options
  • Save DanNi0130/b917e4df7f4c87369a20299ef5874472 to your computer and use it in GitHub Desktop.
Save DanNi0130/b917e4df7f4c87369a20299ef5874472 to your computer and use it in GitHub Desktop.
const rp = require('request-promise');
const $ = require('cheerio');
const potusParse = require('./potusParse');
const url = 'https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States';
rp(url)
.then(function(html) {
//success!
const wikiUrls = [];
for (let i = 0; i < 45; i++) {
wikiUrls.push($('big > a', html)[i].attribs.href);
}
return Promise.all(
wikiUrls.map(function(url) {
return potusParse('https://en.wikipedia.org' + url);
})
);
})
.then(function(presidents) {
console.log(presidents);
})
.catch(function(err) {
//handle error
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment