-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (27 loc) · 805 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const requestPromise = require("request-promise");
const $ = require("cheerio");
const script = require("./script");
const url =
"https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States";
requestPromise(url)
.then((html) => {
// console.log("html", html);
const wikiUrls = [];
for (let i = 0; i < $("big > a", html).length; i++) {
wikiUrls.push($("big>a", html)[i].attribs.href);
}
console.log("wiki urls", wikiUrls);
return Promise.all(
wikiUrls.map((url) => {
return script("https://en.wikipedia.org" + url);
})
);
// console.log($("big > a", html).length);
// console.log($("big > a", html));
})
.then(function(presidents) {
console.log(presidents);
})
.catch((err) => {
console.log("err", err);
});