Created
July 19, 2018 01:35
-
-
Save DanNi0130/b917e4df7f4c87369a20299ef5874472 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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