-
Notifications
You must be signed in to change notification settings - Fork 0
/
eksi.js
36 lines (31 loc) · 1011 Bytes
/
eksi.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
var request = require('request');
var HTMLParser = require('node-html-parser');
async function getHtml(url) {
return new Promise((resolve, reject) => {
var options = {
'method': 'GET',
'url': url
};
request(options, function (error, response) {
if (error) reject(error);
else {
resolve(response.body)
}
});
});
}
exports.getEntries = async function (url, pageNumber) {
var html = await getHtml(url + "?p=" + pageNumber);
var root = HTMLParser.parse(html);
var entries = root.querySelectorAll('#entry-item');
let list = []
for (var i = 0; i < entries.length; i++) {
let content = entries[i].querySelector(".content").toString();
content = content.replace(/<[^>]*>?/gm, '');
content = content.trim();
//console.log(content);
//console.log("-----------")
if (content.length < 500) list.push(content);
}
return list;
}