use WuxiaWorld api & cheerio instead of puppeteer
This commit is contained in:
@@ -1,39 +1,37 @@
|
||||
const express = require("express");
|
||||
const cheerio = require("cheerio");
|
||||
const request = require("request");
|
||||
const chromium = require("chrome-aws-lambda");
|
||||
const puppeteer = require("puppeteer");
|
||||
const { scraper } = require("../../helper");
|
||||
|
||||
const baseUrl = "https://www.wuxiaworld.com/";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/novels/", async (req, res) => {
|
||||
let url = `https://www.wuxiaworld.com/novels`;
|
||||
const body = await scraper(url);
|
||||
let url = `https://www.wuxiaworld.com/api/novels`;
|
||||
|
||||
request(url, (err, response, body) => {
|
||||
if (err) throw err;
|
||||
|
||||
let novels = [];
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
let data = JSON.parse(body);
|
||||
data = data.items;
|
||||
|
||||
$(".novel-item").each(function (result) {
|
||||
let novelName = $(this).find("div.novel-title").text();
|
||||
let novelCover = $(this).find("img").attr("src");
|
||||
let novelUrl = $(this).find("a").attr("href");
|
||||
novelUrl = novelUrl.replace("/novel/", "").concat("/");
|
||||
data.map((novel) => {
|
||||
let novelName = novel.name;
|
||||
let novelCover = novel.coverUrl;
|
||||
let novelUrl = novel.slug;
|
||||
novelUrl = novelUrl + "/";
|
||||
|
||||
novel = {
|
||||
novels.push({
|
||||
extensionId: 7,
|
||||
novelUrl,
|
||||
novelName,
|
||||
novelCover,
|
||||
novelUrl,
|
||||
};
|
||||
|
||||
novels.push(novel);
|
||||
});
|
||||
|
||||
});
|
||||
res.json(novels);
|
||||
});
|
||||
});
|
||||
|
||||
// Novel
|
||||
@@ -41,8 +39,9 @@ router.get("/novels/", async (req, res) => {
|
||||
router.get("/novel/:novelUrl", async (req, res) => {
|
||||
let novelUrl = req.params.novelUrl;
|
||||
let url = `${baseUrl}novel/${novelUrl}/`;
|
||||
const body = await scraper(url);
|
||||
|
||||
request(url, (err, response, body) => {
|
||||
if (err) throw err;
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
let novel = {};
|
||||
@@ -102,6 +101,7 @@ router.get("/novel/:novelUrl", async (req, res) => {
|
||||
novel.novelChapters = novelChapters;
|
||||
|
||||
res.json(novel);
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/novel/:novelUrl/:chapterUrl", async (req, res) => {
|
||||
@@ -109,8 +109,9 @@ router.get("/novel/:novelUrl/:chapterUrl", async (req, res) => {
|
||||
|
||||
const novelUrl = `${req.params.novelUrl}/`;
|
||||
const chapterUrl = `${req.params.chapterUrl}/`;
|
||||
const body = await scraper(url);
|
||||
|
||||
request(url, (err, response, body) => {
|
||||
if (err) throw err;
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
let chapterName = $("#sidebar-toggler-container").next().text();
|
||||
@@ -144,6 +145,7 @@ router.get("/novel/:novelUrl/:chapterUrl", async (req, res) => {
|
||||
};
|
||||
|
||||
res.json(chapter);
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/search/", (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user