mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 14:07:54 +08:00
@@ -784,6 +784,20 @@ rule
|
||||
|
||||
<Route author="hillerliao" example="/xueqiu/hots" path="/xueqiu/hots"/>
|
||||
|
||||
## 小红书
|
||||
|
||||
### 用户笔记和专辑
|
||||
|
||||
<Route author="lotosbin" example="/xiaohongshu/user/593032945e87e77791e03696/notes" path="/xiaohongshu/user/:user_id/notes" :paramsDesc="['user_id']"/>
|
||||
|
||||
### 用户专辑
|
||||
|
||||
<Route author="lotosbin" example="/xiaohongshu/user/593032945e87e77791e03696/album" path="/xiaohongshu/user/:user_id/album" :paramsDesc="['user_id']"/>
|
||||
|
||||
### 专辑
|
||||
|
||||
<Route author="lotosbin" example="/xiaohongshu/board/5db6f79200000000020032df" path="/xiaohongshu/board/:board_id" :paramsDesc="['board_id']" />
|
||||
|
||||
## 知乎
|
||||
|
||||
### 收藏夹
|
||||
|
||||
@@ -1953,6 +1953,10 @@ router.get('/zhanqi/room/:id', require('./routes/zhanqi/room'));
|
||||
// 酒云网
|
||||
router.get('/wineyun/:category', require('./routes/wineyun'));
|
||||
|
||||
// 小红书
|
||||
router.get('/xiaohongshu/user/:user_id/:category', require('./routes/xiaohongshu/user'));
|
||||
router.get('/xiaohongshu/board/:board_id', require('./routes/xiaohongshu/board'));
|
||||
|
||||
// 重磅原创-每经网
|
||||
router.get('/nbd/daily', require('./routes/nbd/article'));
|
||||
|
||||
|
||||
28
lib/routes/xiaohongshu/board.js
Normal file
28
lib/routes/xiaohongshu/board.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { getContent } = require('@/routes/xiaohongshu/util');
|
||||
|
||||
const JSON5 = require('json5');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `https://www.xiaohongshu.com/board/${ctx.params.board_id}`;
|
||||
const content = await getContent(url);
|
||||
const regex = /_SSR_STATE__\S*=([\s\S]+)<\/script>/gm;
|
||||
const match = regex.exec(content);
|
||||
const main = JSON5.parse(match[1]).Main;
|
||||
|
||||
const albumInfo = main.albumInfo;
|
||||
const title = `${albumInfo.name}`;
|
||||
const description = `${albumInfo.desc}`;
|
||||
|
||||
const list = main.notesDetail;
|
||||
const resultItem = list.map((item) => ({
|
||||
title: `${item.title}`,
|
||||
link: `https://www.xiaohongshu.com/discovery/item/${item.id}`,
|
||||
description: `<img src ="${item.cover.url}"><br>${item.title}`,
|
||||
}));
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: resultItem,
|
||||
description: description,
|
||||
};
|
||||
};
|
||||
49
lib/routes/xiaohongshu/user.js
Normal file
49
lib/routes/xiaohongshu/user.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const { getContent } = require('@/routes/xiaohongshu/util');
|
||||
|
||||
const cheerio = require('cheerio');
|
||||
const JSON5 = require('json5');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const userId = ctx.params.user_id;
|
||||
const category = ctx.params.category;
|
||||
const url = `https://www.xiaohongshu.com/user/profile/${userId}`;
|
||||
|
||||
const content = await getContent(url);
|
||||
const $ = cheerio.load(content);
|
||||
const description = $('head title');
|
||||
const regex = /_SSR_STATE__\S*=([\s\S]+)<\/script>/gm;
|
||||
const match = regex.exec(content);
|
||||
const main = JSON5.parse(match[1]).Main;
|
||||
const userDetail = main.userDetail;
|
||||
if (category === 'notes') {
|
||||
const list = main.notesDetail;
|
||||
const resultItem = list.map((item) => ({
|
||||
title: `${item.title}`,
|
||||
link: `${item.link}`,
|
||||
description: `<img src ="${item.cover.url}"><br>${item.title}`,
|
||||
}));
|
||||
|
||||
const title = `小红书-${userDetail.nickname}-笔记`;
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: resultItem,
|
||||
description: description,
|
||||
};
|
||||
} else if (category === 'album') {
|
||||
const list = main.albumDetail;
|
||||
const resultItem = list.map((item) => ({
|
||||
title: `${item.title}`,
|
||||
link: `https://www.xiaohongshu.com/board/${item.id}`,
|
||||
description: item.images.map((it) => `<img src ="${it}">`).join(`<br />`),
|
||||
}));
|
||||
|
||||
const title = `小红书-${userDetail.nickname}-专辑`;
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: resultItem,
|
||||
description: description,
|
||||
};
|
||||
}
|
||||
};
|
||||
18
lib/routes/xiaohongshu/util.js
Normal file
18
lib/routes/xiaohongshu/util.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const delay = (timeout = 1000) => new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
|
||||
async function getContent(url) {
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
try {
|
||||
const page = await browser.newPage();
|
||||
await page.goto(url);
|
||||
await delay(1000);
|
||||
const content = await page.content();
|
||||
return content.replace('"RedAppLayout":undefined,', ''); // fix json parse
|
||||
} finally {
|
||||
browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getContent,
|
||||
};
|
||||
Reference in New Issue
Block a user