-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.js
23 lines (18 loc) · 778 Bytes
/
c.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// marks 20%
const fetch = require('node-fetch');
const cheerio = require('cheerio');
// node-fetch is a library that allows you to make http requests in node. It's already listed in the package.json so just run `npm i` to install it
// install the cheerio library and use it to get all the text within every anchor tag at this URL: http://home.mcom.com/home/welcome.html
function c() {
return fetch('http://home.mcom.com/home/welcome.html')
.then(res => res.text())
.then(html => {
const $ = cheerio.load(html);
const anchorTags = $('a');
const texts = anchorTags.map((index, anchor) => $(anchor).text()).get();
const toString = texts.join("");
return toString;
})
.catch(err => console.error(err));
}
module.exports = c;