fix(route): baidu top (#11754)

This commit is contained in:
Tony 2023-02-01 18:05:51 +00:00 committed by GitHub
parent 2ae299f978
commit 69ba50d69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 46 deletions

View File

@ -396,7 +396,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 发现用户
<Route author="sanmmm" example="/afdian/explore/hot/所有" path="/afdian/explore/:type/:category?" :paramsDesc="['分类', '目录类型, 默认为 `所有`']">
<Route author="sanmmm" example="/afdian/explore/hot/所有" path="/afdian/explore/:type/:category?" :paramsDesc="['分类', '目录类型默认为 `所有`']">
分类
| 推荐 | 最热 |
@ -413,7 +413,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 用户动态
<Route author="sanmmm" example="/afdian/dynamic/@afdian" path="/afdian/dynamic/:uid?" :paramsDesc="['用户id, 用户动态页面url里可找到']"/>
<Route author="sanmmm" example="/afdian/dynamic/@afdian" path="/afdian/dynamic/:uid?" :paramsDesc="['用户id用户动态页面url里可找到']"/>
## 澳門特別行政區政府各公共部門獎助貸學金服務平台
@ -427,15 +427,15 @@ type 为 all 时category 参数不支持 cost 和 free
</Route>
## 百度搜索风云榜
## 百度
### 榜单
<Route author="xyqfer" example="/baidu/topwords/1" path="/baidu/topwords/:boardId?" :paramsDesc="['榜单 id, 默认为`1`']">
<Route author="xyqfer" example="/baidu/top" path="/baidu/top/:board?" :paramsDesc="['榜单,默认为 `realtime`']" radar="1">
| 实时热点 | 今日热点 | 七日热点 | 民生热点 | 娱乐热点 | 体育热点 |
| ---- | ---- | ---- | ---- | ---- | ---- |
| 1 | 341 | 42 | 342 | 344 | 11 |
| 热搜榜 | 小说榜 | 电影榜 | 电视剧榜 | 汽车榜 | 游戏榜 |
| -------- | ----- | ----- | -------- | --- | ---- |
| realtime | novel | movie | teleplay | car | game |
</Route>

View File

@ -950,7 +950,7 @@ router.get('/geekpark/breakingnews', lazyloadRouteHandler('./routes/geekpark/bre
// 百度
router.get('/baidu/doodles', lazyloadRouteHandler('./routes/baidu/doodles'));
router.get('/baidu/topwords/:boardId?', lazyloadRouteHandler('./routes/baidu/topwords'));
// router.get('/baidu/topwords/:boardId?', lazyloadRouteHandler('./routes/baidu/topwords'));
router.get('/baidu/daily', lazyloadRouteHandler('./routes/baidu/daily'));
// 搜狗

View File

@ -1,38 +0,0 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const { boardId = 1 } = ctx.params;
const response = await got({
method: 'get',
url: `http://top.baidu.com/mobile_v2/buzz?b=${boardId}`,
});
const { board, topwords, descs } = response.data.result;
const items = topwords.map((item, index) => {
const title = item.keyword;
const content = descs[index].content;
const desc = content
? content.data[0]
: {
originlink: `https://www.baidu.com/s?ie=utf-8&wd=${encodeURIComponent(title)}`,
title,
description: title,
pubDate: Date.now(),
};
return {
title,
description: `
<a href="${desc.originlink}">${desc.title}</a><br>
${desc.description || ''}
`,
link: desc.originlink,
pubDate: new Date(desc.pubDate).toUTCString(),
};
});
ctx.state.data = {
title: `百度搜索风云榜-${board.boardname}`,
item: items,
};
};

View File

@ -5,4 +5,5 @@ module.exports = {
'/tieba/post/:id': ['u3u'],
'/tieba/post/lz/:id': ['u3u'],
'/tieba/user/:uid': ['igxlin', 'nczitzk'],
'/top/:board?': ['xyqfer'],
};

View File

@ -56,5 +56,13 @@ module.exports = {
},
},
],
top: [
{
title: '热搜榜单',
docs: 'https://docs.rsshub.app/other.html#bai-du-re-sou',
source: ['/board'],
target: (_, url) => `/baidu/top/${new URL(url).searchParams.get('tab')}`,
},
],
},
};

View File

@ -5,4 +5,5 @@ module.exports = (router) => {
router.get('/tieba/post/:id', require('./tieba/post'));
router.get('/tieba/post/lz/:id', require('./tieba/post'));
router.get('/tieba/user/:uid', require('./tieba/user'));
router.get('/top/:board?', require('./top'));
};

View File

@ -0,0 +1,9 @@
{{ if item.img }}
<img src="{{ item.img }}"><br>
{{ /if }}
{{ if item.show }}
{{ each item.show s }}
{{ s }}<br>
{{ /each }}
{{ /if }}
{{ item.desc }}

34
lib/v2/baidu/top.js Normal file
View File

@ -0,0 +1,34 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const { board = 'realtime' } = ctx.params;
const link = `https://top.baidu.com/board?tab=${board}`;
const { data: response } = await got(link);
const $ = cheerio.load(response);
const { data } = JSON.parse(
$('#sanRoot')
.contents()
.filter((e) => e.nodeType === 8)
.prevObject[0].data.match(/s-data:(.*)/)[1]
);
const items = data.cards[0].content.map((item) => ({
title: item.word,
description: art(path.join(__dirname, 'templates/top.art'), {
item,
}),
link: item.rawUrl,
}));
ctx.state.data = {
title: `${data.curBoardName} - 百度热搜`,
description: $('meta[name="description"]').attr('content'),
link,
item: items,
};
};