mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
✨ feat: 新增部分接口
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* @author: x-dr
|
||||
* @date: 2023年12月26日
|
||||
* @tags: [豆瓣讨论精选]
|
||||
* @author: x-dr
|
||||
* @date: 2023-12-26
|
||||
* @customEditors: imsyy
|
||||
* @lastEditTime: 2024-01-02
|
||||
*/
|
||||
|
||||
|
||||
const Router = require("koa-router");
|
||||
const doubanGroupNewRouter = new Router();
|
||||
const axios = require("axios");
|
||||
@@ -13,13 +13,11 @@ const { get, set, del } = require("../utils/cacheData");
|
||||
|
||||
// 接口信息
|
||||
const routerInfo = {
|
||||
name: "doubangroup",
|
||||
name: "douban_group",
|
||||
title: "豆瓣讨论小组",
|
||||
subtitle: "精选",
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 缓存键名
|
||||
const cacheKey = "doubanGroupData";
|
||||
|
||||
@@ -29,12 +27,13 @@ let updateTime = new Date().toISOString();
|
||||
const url = "https://www.douban.com/group/explore";
|
||||
|
||||
const headers = {
|
||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
accept:
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||
"cache-control": "max-age=0",
|
||||
"sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Google Chrome\";v=\"120\"",
|
||||
"sec-ch-ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"sec-ch-ua-platform": "\"Windows\"",
|
||||
"sec-ch-ua-platform": '"Windows"',
|
||||
"sec-fetch-dest": "document",
|
||||
"sec-fetch-mode": "navigate",
|
||||
"sec-fetch-site": "none",
|
||||
@@ -43,27 +42,31 @@ const headers = {
|
||||
// "cookie": "bid=lLpb6D1JLuw; douban-fav-remind=1; _pk_id.100001.8cb4=e7d91ae46530fd1d.1680518589.; ll=\"118281\"; _pk_ref.100001.8cb4=%5B%22%22%2C%22%22%2C1703602972%2C%22http%3A%2F%2Fnew.xianbao.fun%2F%22%5D; _pk_ses.100001.8cb4=1; ap_v=0,6.0"
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 数据处理
|
||||
const getData = (data) => {
|
||||
if (!data) return false;
|
||||
const dataList = [];
|
||||
const $ = cheerio.load(data);
|
||||
try {
|
||||
|
||||
$(`.channel-item`).each((i, e) => {
|
||||
// console.log($(e).html());
|
||||
const item= cheerio.load($(e).html())
|
||||
const title = item("h3").text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const url = item("h3 a").attr('href')
|
||||
const hot= item('div[class="likes"]').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const desc = item('div[class="block"]').text().replace(/(^\s*)|(\s*$|\n)/g, "")
|
||||
const source = item('div[class="source"] a').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
const item = cheerio.load($(e).html());
|
||||
const title = item("h3")
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const url = item("h3 a").attr("href");
|
||||
const hot = item('div[class="likes"]')
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
const desc = item('div[class="block"]')
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$|\n)/g, "");
|
||||
const source = item('div[class="source"] a')
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, "");
|
||||
// const excerpt = item('.channel-item-desc').text().replace(/(^\s*)|(\s*$)/g, "")
|
||||
// console.log(title);
|
||||
// console.log(url);
|
||||
|
||||
dataList.push({
|
||||
title: title,
|
||||
desc: desc,
|
||||
@@ -71,9 +74,7 @@ const getData = (data) => {
|
||||
mobileUrl: url,
|
||||
hot: hot,
|
||||
source: source,
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
return dataList;
|
||||
} catch (error) {
|
||||
@@ -82,10 +83,8 @@ const getData = (data) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// trending
|
||||
doubanGroupNewRouter.get("/doubangroup", async (ctx) => {
|
||||
doubanGroupNewRouter.get("/douban_group", async (ctx) => {
|
||||
console.log("获取豆瓣讨论小组精选");
|
||||
try {
|
||||
// 从缓存中获取数据
|
||||
@@ -130,11 +129,8 @@ doubanGroupNewRouter.get("/doubangroup", async (ctx) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// 豆瓣新片榜 - 获取最新数据
|
||||
doubanGroupNewRouter.get("/doubangroup/new", async (ctx) => {
|
||||
doubanGroupNewRouter.get("/douban_group/new", async (ctx) => {
|
||||
console.log("获取豆瓣讨论小组精选 - 最新数据");
|
||||
try {
|
||||
// 从服务器拉取最新数据
|
||||
@@ -182,4 +178,4 @@ doubanGroupNewRouter.get("/doubangroup/new", async (ctx) => {
|
||||
});
|
||||
|
||||
doubanGroupNewRouter.info = routerInfo;
|
||||
module.exports = doubanGroupNewRouter;
|
||||
module.exports = doubanGroupNewRouter;
|
||||
|
||||
Reference in New Issue
Block a user