From a18f3fca140117486db7153d177d40de6c1e7fa5 Mon Sep 17 00:00:00 2001 From: Moe Date: Sat, 19 Jan 2019 01:16:30 +0700 Subject: [PATCH] Initial Release --- .gitignore | 1 + NekopoiScrapper/getInfo.js | 36 ++++++++++++++++++++++++++++ NekopoiScrapper/getLatest.js | 46 ++++++++++++++++++++++++++++++++++++ NekopoiScrapper/index.js | 13 ++++++++++ example.js | 9 +++++++ 5 files changed, 105 insertions(+) create mode 100644 .gitignore create mode 100644 NekopoiScrapper/getInfo.js create mode 100644 NekopoiScrapper/getLatest.js create mode 100644 NekopoiScrapper/index.js create mode 100644 example.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/NekopoiScrapper/getInfo.js b/NekopoiScrapper/getInfo.js new file mode 100644 index 0000000..457ee26 --- /dev/null +++ b/NekopoiScrapper/getInfo.js @@ -0,0 +1,36 @@ +/** + * @author Moe Poi + * @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; \ No newline at end of file diff --git a/NekopoiScrapper/getLatest.js b/NekopoiScrapper/getLatest.js new file mode 100644 index 0000000..803f14c --- /dev/null +++ b/NekopoiScrapper/getLatest.js @@ -0,0 +1,46 @@ +/** + * @author Moe Poi + * @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; \ No newline at end of file diff --git a/NekopoiScrapper/index.js b/NekopoiScrapper/index.js new file mode 100644 index 0000000..3c4d8a3 --- /dev/null +++ b/NekopoiScrapper/index.js @@ -0,0 +1,13 @@ +/** + * @author Moe Poi + * @license MIT + */ +"use strict"; + +const getLatest = require('./getLatest'); +const getInfo = require('./getInfo'); + +module.exports = { + getLatest, + getInfo +} \ No newline at end of file diff --git a/example.js b/example.js new file mode 100644 index 0000000..a65a49c --- /dev/null +++ b/example.js @@ -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)); \ No newline at end of file