55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
const { http, utils, db, config,router } = require("../../_");
|
|
|
|
// http://127.0.0.1:3000/api/json/1.0/class?class=1&page=1
|
|
router.get('/class', async function(req,res,next){
|
|
|
|
// 请求数据 and 返回dom数据
|
|
let $ = await utils.AnalyticalData({ class:req.query.class, page: req.query.page } ),
|
|
left = [],
|
|
father = null;
|
|
|
|
/**
|
|
* 存在 action 爬取每个分类下面的更多小说
|
|
*/
|
|
if(req.query.hasOwnProperty("action")){
|
|
|
|
// http://127.0.0.1:3000/api/json/1.0/class?class=2&page=1&action=more
|
|
father = $("#newscontent .l ul li")
|
|
father.each(function(){
|
|
left.push({
|
|
title: $(this).find(".s2 a").text(),
|
|
url: $(this).find(".s2 a").attr("href")
|
|
})
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
* 不存在 action 爬取每个分类小面的推荐小说
|
|
*/
|
|
} else {
|
|
// http://127.0.0.1:3000/api/json/1.0/class?class=2
|
|
father = $("#hotcontent .ll .item")
|
|
|
|
// 插入数据之前先删除之前的数据
|
|
// await db.Query({ sql: config.sql.index.delete, par: [ req.query.class ] });
|
|
father.each(async function() {
|
|
left.push({
|
|
title: $(this).find("dl dt a").text(),
|
|
imgURL: $(this).find(".image img").attr("src"),
|
|
author: $(this).find("dl dt span").text(),
|
|
introduce: $(this).find("dl dd").text(),
|
|
url: $(this).find(".image a").attr("href")
|
|
})
|
|
})
|
|
|
|
}
|
|
|
|
return res.json(left)
|
|
|
|
|
|
})
|
|
|
|
|
|
module.exports = router
|