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