-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 1017 Bytes
/
index.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
30
31
32
33
34
35
36
const ArticleParser = require("article-parser");
const HtmlToText = require("html-to-text");
const fs = require("fs");
const articlesUrls = [
"https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%BE%D0%B5%D0%BA%D1%82_%C2%AB%D0%93%D0%B5%D0%BD%D0%BE%D0%BC_%D1%87%D0%B5%D0%BB%D0%BE%D0%B2%D0%B5%D0%BA%D0%B0%C2%BB"
];
async function getArticlesContent() {
const articlesContents = [];
for (let articleUrl of articlesUrls) {
const articleData = await ArticleParser.extract(articlesUrls[0]);
articlesContents.push(HtmlToText.htmlToText(articleData.content, {
selectors: [
{
selector: 'a',
options: {
ignoreHref: true
}
}
]
}));
}
return articlesContents;
}
getArticlesContent().then(articles => {
//console.log(articles)
fs.writeFile("article.txt", articles[0], err => {
if (err) {
throw err;
}
});
});