80 lines
2.5 KiB
JavaScript
80 lines
2.5 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const $http = require('../http');
|
|
const config = require('../config');
|
|
const utils = require('../utils');
|
|
|
|
router.get('/', async function(req, res, next) {
|
|
try {
|
|
let $ = utils.cheerioLoad(await $http.get({ url: config.HomeUrl }));
|
|
let MainData = {
|
|
banner: [],
|
|
booklist: []
|
|
};
|
|
// 抓取banner轮播图数据
|
|
let BannerData = []
|
|
$(".slider-top-pic li").each(function() {
|
|
BannerData.push({
|
|
imgUrl: $(this).find('img').attr("src"),
|
|
href: 'https://m.zongheng.com' + $(this).attr("data-url")
|
|
})
|
|
});
|
|
MainData.banner = BannerData
|
|
|
|
// 抓取 编辑力荐begin 的数据
|
|
let HomeTop = {}
|
|
HomeTop.title = $(".home-top .home-card-title i").text()
|
|
HomeTop.list = []
|
|
$('.home-top .home-book-item').each(function() {
|
|
HomeTop.list.push({
|
|
imgUrl: $(this).find("img").attr("src"),
|
|
title: $(this).find("img").attr("alt"),
|
|
id: utils.getUrlParam($(this).attr("data-url"),"bookid"),
|
|
desc: $(this).find(".desc").text(),
|
|
class: $(this).find(".item-label").text()
|
|
})
|
|
});
|
|
MainData.booklist.push(HomeTop)
|
|
|
|
// 男生必读 & 女生爱看
|
|
let HomeBoy = {}
|
|
HomeBoy.title = $(".home-boy .home-card-title i").text()
|
|
HomeBoy.list = []
|
|
$('.home-boy .home-book-box').each(function() {
|
|
HomeBoy.list.push({
|
|
imgUrl: $(this).find("img").attr("data-src"),
|
|
title: $(this).find("img").attr("alt"),
|
|
id: utils.getUrlParam($(this).attr("data-url"),"bookid"),
|
|
desc: "",
|
|
class: ""
|
|
})
|
|
});
|
|
MainData.booklist.push(HomeBoy)
|
|
|
|
|
|
// 仙侠奇幻
|
|
let xianBook = {}
|
|
let xian = $(".home-card")[3]
|
|
xianBook.title = $(xian).find(".home-card-title .flex--fluid").text()
|
|
xianBook.top = {
|
|
imgUrl: $(xian).find(".book-img-border img").attr("data-src"),
|
|
title: $(xian).find(".font-a").text(),
|
|
id: utils.getUrlParam($(xian).find(".home-book-item").attr("data-url"),"bookid"),
|
|
desc: $(xian).find(".desc").text(),
|
|
class: $(xian).find(".item-label").text(),
|
|
}
|
|
xianBook.list = []
|
|
$(xian).find(".home-row-line").each(function() {
|
|
xianBook.list.push({
|
|
title: $(this).find("span").text(),
|
|
id: utils.getUrlParam($(this).attr("href"),"bookid")
|
|
})
|
|
})
|
|
MainData.booklist.push(xianBook)
|
|
utils.JsonData({ res: res, status: 200, data: MainData })
|
|
} catch (error) {
|
|
utils.JsonData({ res: res, status: 404, data: error.message })
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|