Initial Release

This commit is contained in:
Moe Poi ~ 2019-01-19 01:16:30 +07:00
parent f5dc6bdf0d
commit a18f3fca14
5 changed files with 105 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.idea/

View file

@ -0,0 +1,36 @@
/**
* @author Moe Poi <moepoi@protonmail.com>
* @license MIT
*/
"use strict";
const axios = require('axios');
const cheerio = require('cheerio');
let links = [];
const getInfo = (url) => {
return new Promise((resolve, reject) => {
axios.get(url).then(function(req) {
let soup = cheerio.load(req.data);
var title = soup("title").text();
soup('div.liner').each(function(i, e) {
soup(e).find('div.listlink').each(function(j, s) {
links.push(soup(s).find('a').attr('href'))
});
});
var data = {
"title": title,
"links": links
};
if (data == null) {
reject("No result :(");
} else {
var result = JSON.stringify(data, null, 2);
resolve(result);
}
});
});
};
module.exports = getInfo;

View file

@ -0,0 +1,46 @@
/**
* @author Moe Poi <moepoi@protonmail.com>
* @license MIT
*/
"use strict";
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);
soup('div.eropost').each(function(i, e) {
soup(e).find('h2').each(function(j, s) {
title.push(soup(s).find('a').text().trim());
link.push(url + soup(s).find('a').attr('href'));
});
image.push(url + soup(e).find('img').attr('src'));
});
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 == null) {
reject("No result :(");
} else {
var result = JSON.stringify(data, null, 2);
resolve(result);
}
});
});
};
module.exports = getLatest;

13
NekopoiScrapper/index.js Normal file
View file

@ -0,0 +1,13 @@
/**
* @author Moe Poi <moepoi@protonmail.com>
* @license MIT
*/
"use strict";
const getLatest = require('./getLatest');
const getInfo = require('./getInfo');
module.exports = {
getLatest,
getInfo
}

9
example.js Normal file
View file

@ -0,0 +1,9 @@
const NekopoiScrapper = require('./NekopoiScrapper');
// Latest Release
NekopoiScrapper.getLatest()
.then((data) => console.log(data));
// Get Page Info
NekopoiScrapper.getInfo("http://nekopoi.cash/dokidoki-little-ooyasan-episode-4-subtitle-indonesia")
.then((data) => console.log(data));