mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-19 09:52:21 +08:00
feat(route): 添加百度贴吧搜索 (#13238)
* feat(route): add baidu tieba search * fix(route): delete ctx.query.limit in case of problems * fix(route): replace outdated querystring with URLSearchParams * fix(route): 修复中文乱码 * Update lib/v2/baidu/tieba/search.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * chore(route): rename variable ---------
This commit is contained in:
@@ -4,6 +4,7 @@ module.exports = {
|
||||
'/tieba/forum/:kw/:sortBy?': ['u3u'],
|
||||
'/tieba/post/:id': ['u3u'],
|
||||
'/tieba/post/lz/:id': ['u3u'],
|
||||
'/tieba/search/:qw/:routeParams?': ['JimenezLi'],
|
||||
'/tieba/user/:uid': ['igxlin', 'nczitzk'],
|
||||
'/top/:board?': ['xyqfer'],
|
||||
};
|
||||
|
||||
+15
-1
@@ -46,7 +46,7 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
title: '用户帖子',
|
||||
docs: 'https://docs.rsshub.app/routes/bbs#tie-ba',
|
||||
docs: 'https://docs.rsshub.app/routes/bbs#bai-du-tie-ba',
|
||||
source: '/home/main',
|
||||
target: (params, url) => {
|
||||
const uid = new URL(url).searchParams.get('un');
|
||||
@@ -55,6 +55,20 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '贴吧搜索',
|
||||
docs: 'https://docs.rsshub.app/routes/bbs#bai-du-tie-ba',
|
||||
source: '/f/search/res',
|
||||
target: (params, url) => {
|
||||
const searchParams = new URL(url).searchParams;
|
||||
const qw = searchParams.get('qw');
|
||||
const kw = searchParams.get('kw');
|
||||
if (qw) {
|
||||
const route = `/baidu/tieba/user/${qw}`;
|
||||
return kw ? `${route}/kw=${kw}` : route;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
top: [
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ module.exports = (router) => {
|
||||
router.get('/tieba/forum/:kw/:sortBy?', require('./tieba/forum'));
|
||||
router.get('/tieba/post/:id', require('./tieba/post'));
|
||||
router.get('/tieba/post/lz/:id', require('./tieba/post'));
|
||||
router.get('/tieba/search/:qw/:routeParams?', require('./tieba/search'));
|
||||
router.get('/tieba/user/:uid', require('./tieba/user'));
|
||||
router.get('/top/:board?', require('./top'));
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<p>{{ details }}</p><p>{{@ medias }}</p><p>贴吧:{{ tieba }}<br/>作者:{{ author }}</p>
|
||||
@@ -0,0 +1,63 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const iconv = require('iconv-lite');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const qw = ctx.params.qw;
|
||||
const query = new URLSearchParams(ctx.params.routeParams);
|
||||
query.set('ie', 'utf-8');
|
||||
query.set('qw', qw);
|
||||
query.set('rn', query.get('rn') || 20); // Number of returned items
|
||||
const link = `https://tieba.baidu.com/f/search/res?${query.toString()}`;
|
||||
|
||||
const response = await got.get(link, {
|
||||
headers: {
|
||||
Referer: 'https://tieba.baidu.com',
|
||||
},
|
||||
responseType: 'buffer',
|
||||
});
|
||||
const data = iconv.decode(response.data, 'gbk');
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const resultList = $('div.s_post');
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${qw} - ${query.get('kw') || '百度贴'}吧搜索`,
|
||||
link,
|
||||
item: resultList.toArray().map((element) => {
|
||||
const item = $(element);
|
||||
const titleItem = item.find('.p_title a');
|
||||
const title = titleItem.text().trim();
|
||||
const link = titleItem.attr('href');
|
||||
const time = item.find('.p_date').text().trim();
|
||||
const details = item.find('.p_content').text().trim();
|
||||
const medias = item
|
||||
.find('.p_mediaCont img')
|
||||
.toArray()
|
||||
.map((element) => {
|
||||
const item = $(element);
|
||||
return `<img src="${item.attr('original')}">`;
|
||||
})
|
||||
.join('');
|
||||
const tieba = item.find('a.p_forum').text().trim();
|
||||
const author = item.find('a').last().text().trim();
|
||||
|
||||
return {
|
||||
title,
|
||||
description: art(path.join(__dirname, '../templates/tieba_search.art'), {
|
||||
details,
|
||||
medias,
|
||||
tieba,
|
||||
author,
|
||||
}),
|
||||
author,
|
||||
pubDate: timezone(parseDate(time, 'YYYY-MM-DD HH:mm'), +8),
|
||||
link,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
@@ -480,6 +480,21 @@ When accessing Joeyray's Bar, `SCBOY_BBS_TOKEN` needs to be filled in `environme
|
||||
|
||||
</Route>
|
||||
|
||||
### 贴吧搜索 {#bai-du-tie-ba-tie-ba-sou-suo}
|
||||
|
||||
<Route author="JimenezLi" example="/baidu/tieba/search/neuro" path="/baidu/tieba/search/:qw/:routeParams?" paramsDesc={['搜索关键词', '额外参数;请参阅以下说明和表格']} radar="1">
|
||||
|
||||
| 键 | 含义 | 接受的值 | 默认值 |
|
||||
| -- | ---- | ------- | ------ |
|
||||
| kw | 在名为 kw 的贴吧中搜索 | 任意名称/无 | 无 |
|
||||
| only_thread | 只看主题帖,默认为 0 关闭 | 0/1 | 0 |
|
||||
| rn | 返回条目的数量 | 1-20 | 20 |
|
||||
| sm | 排序方式,0 为按时间顺序,1 为按时间倒序,2 为按相关性顺序 | 0/1/2 | 1 |
|
||||
|
||||
用例:`/baidu/tieba/search/neuro/kw=neurosama&only_thread=1&sm=2`
|
||||
|
||||
</Route>
|
||||
|
||||
## 才符 {#cai-fu}
|
||||
|
||||
### 用户动态 {#cai-fu-yong-hu-dong-tai}
|
||||
|
||||
Reference in New Issue
Block a user