Add all_novels route

This commit is contained in:
Rajarshee Chatterjee
2020-12-24 20:32:15 +05:30
parent 15e726fb1d
commit 749760344f
3 changed files with 44 additions and 10 deletions
+37
View File
@@ -0,0 +1,37 @@
const express = require("express");
const cheerio = require("cheerio");
const request = require("request");
const router = express.Router();
const baseUrl = "https://boxnovel.com/novel/";
router.get("/novels/:pageNo/", (req, res) => {
orderBy = req.query.o;
pageNo = req.params.pageNo;
let novels = [];
url = `${baseUrl}/page/${pageNo}/?m_orderby=${orderBy}`;
request(url, (err, response, body) => {
if (err) throw err;
$ = cheerio.load(body);
$(".page-item-detail").each(function (result) {
novelName = $(this).find("h5 > a").text();
novelCover = $(this).find("img").attr("src");
novelUrl = $(this).find("h5 > a").attr("href").replace(baseUrl, "");
novel = {
novelName: novelName,
novelCover: novelCover,
novelUrl: novelUrl,
};
novels.push(novel);
});
res.json(novels);
});
});
module.exports = router;
+6 -10
View File
@@ -20,15 +20,7 @@ router.get("/novel/:novelUrl", (req, res) => {
.replace(/[\t\n]/g, "")
.trim();
// authorName = $(".author-content")
// .text()
// .replace(/[\t\n]/g, "")
// .trim();
// artistName = $(".artist-content")
// .text()
// .replace(/[\t\n]/g, "")
// .trim();
novelCover = $(".summary_image > a > img").attr("src");
let novelDetails = {};
@@ -47,6 +39,8 @@ router.get("/novel/:novelUrl", (req, res) => {
novelDetails[detailName] = detail;
});
novelSummary = $(".c_000").text();
let novelChapters = [];
$(".wp-manga-chapter").each(function (result) {
@@ -62,13 +56,15 @@ router.get("/novel/:novelUrl", (req, res) => {
.replace(/[\t\n]/g, "")
.trim();
chapterUrl = $(this).find("a").attr("href");
chapterUrl = $(this).find("a").attr("href").replace(baseUrl, "");
novelChapters.push({ chapterName, releaseDate, chapterUrl });
});
novel = {
novelName,
novelCover,
novelSummary,
novelDetails,
novelChapters,
};