Update url & Optimize getLatest

This commit is contained in:
Moe Poi ~ 2020-05-11 17:57:46 +00:00
parent b7770e4483
commit ef2686df6a

View file

@ -7,40 +7,40 @@
const axios = require('axios'); const axios = require('axios');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
let url = 'http://nekopoi.cash';
let title = [];
let link = [];
let image = [];
let data = [];
const getLatest = () => { const getLatest = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(url).then(function(req) { const url = 'http://nekopoi.care';
let soup = cheerio.load(req.data); axios.get(url)
soup('div.eropost').each(function(i, e) { .then(req => {
soup(e).find('h2').each(function(j, s) { const title = [];
title.push(soup(s).find('a').text().trim()); const link = [];
link.push(url + soup(s).find('a').attr('href')); const image = [];
}); const data = [];
image.push(url + soup(e).find('img').attr('src')); const soup = cheerio.load(req.data);
}); soup('div.eropost').each(function(i, e) {
var i; soup(e).find('h2').each(function(j, s) {
for (i = 0; i < title.length; i++) { title.push(soup(s).find('a').text().trim());
let isi = { link.push(url + soup(s).find('a').attr('href'));
"title": title[i], });
"image": image[i], image.push(url + soup(e).find('img').attr('src'));
"link": link[i]
};
data.push(isi);
}
if (data == null) {
reject("No result :(");
} else {
var result = JSON.stringify(data, null, 2);
resolve(result);
}
}); });
}); var i;
for (i = 0; i < title.length; i++) {
let isi = {
"title": title[i],
"image": image[i],
"link": link[i]
};
data.push(isi);
}
if (data == undefined) {
reject("No result :(");
} else {
var result = JSON.stringify(data, null, 2);
resolve(result);
}
});
});
}; };
module.exports = getLatest; module.exports = getLatest;