feat: 北大未名 BBS 全站十大 (#3870)
This commit is contained in:
parent
fd0c920a83
commit
147b31b779
|
|
@ -396,3 +396,6 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
|
|||
- `FANFOU_CONSUMER_SECRET`: 饭否 Consumer Secret
|
||||
- `FANFOU_USERNAME`: 饭否登录用户名、邮箱、手机号
|
||||
- `FANFOU_PASSWORD`: 饭否密码
|
||||
|
||||
- 北大未名 BBS 全站十大
|
||||
- `PKUBBS_COOKIE`: BBS 注册用户登录后的 Cookie 值,获取方式:1.登录后打开论坛首页 2. 打开控制台 3. 刷新 4. 找到 <https://bbs.pku.edu.cn/v2/home.php> 请求 5. 找到请求头中的 Cookie
|
||||
|
|
|
|||
|
|
@ -58,6 +58,18 @@ pageClass: routes
|
|||
|
||||
<Route author="TPOB" example="/pku/cls/lecture" path="/universities/pku/cls/lecture" />
|
||||
|
||||
### 北大未名 BBS 全站十大
|
||||
|
||||
<Route author="wooddance" example="/pku/bbs/hot" path="/universities/pku/bbs/hot">
|
||||
|
||||
::: warning 注意
|
||||
|
||||
论坛部分帖子正文内容的获取需要用户登录后的 Cookie 值,详情见部署页面的配置模块。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 北京航空航天大学
|
||||
|
||||
### 北京航空航天大学
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@ const calculateValue = () => {
|
|||
username: envs.FANFOU_USERNAME,
|
||||
password: envs.FANFOU_PASSWORD,
|
||||
},
|
||||
pkubbs: {
|
||||
cookie: envs.PKUBBS_COOKIE,
|
||||
},
|
||||
};
|
||||
};
|
||||
calculateValue();
|
||||
|
|
|
|||
|
|
@ -586,6 +586,7 @@ router.get('/lit/tw/:name?', require('./routes/universities/lit/tw'));
|
|||
router.get('/pku/eecs/:type?', require('./routes/universities/pku/eecs'));
|
||||
router.get('/pku/rccp/mzyt', require('./routes/universities/pku/rccp/mzyt'));
|
||||
router.get('/pku/cls/lecture', require('./routes/universities/pku/cls/lecture'));
|
||||
router.get('/pku/bbs/hot', require('./routes/universities/pku/bbs/hot'));
|
||||
|
||||
// 上海海事大学
|
||||
router.get('/shmtu/www/:type', require('./routes/universities/shmtu/www'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
const config = require('@/config').value;
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const resolveUrl = require('url').resolve;
|
||||
|
||||
function parseDate(text) {
|
||||
const match = /[0-9 :-]+/.exec(text);
|
||||
if (match) {
|
||||
return new Date(match[0]).toUTCString();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cookie = config.pkubbs.cookie;
|
||||
const headers = {};
|
||||
if (cookie) {
|
||||
headers.cookie = cookie;
|
||||
}
|
||||
const r = await got('https://bbs.pku.edu.cn/v2/hot-topic.php', { headers });
|
||||
const $ = cheerio.load(r.body);
|
||||
const listItems = $('#list-content .list-item')
|
||||
.map(function() {
|
||||
return {
|
||||
url: resolveUrl(
|
||||
r.url,
|
||||
$(this)
|
||||
.find('> a.link')
|
||||
.attr('href')
|
||||
),
|
||||
title: $(this)
|
||||
.find('.title')
|
||||
.text(),
|
||||
};
|
||||
})
|
||||
.get()
|
||||
.slice(0, 10);
|
||||
|
||||
const item = await Promise.all(
|
||||
listItems.map(
|
||||
async ({ url, title }) =>
|
||||
await ctx.cache.tryGet(url, async () => {
|
||||
// try catch 处理部分无 Cookie 时无法访问的帖子
|
||||
try {
|
||||
const r = await got(url, { headers });
|
||||
const $ = cheerio.load(r.body);
|
||||
return {
|
||||
title,
|
||||
description: $('.post-card:first-child .content').html(),
|
||||
link: url,
|
||||
guid: url,
|
||||
pubDate: parseDate($('.post-card:first-child .sl-triangle-container .title span').text()),
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
title,
|
||||
link: url,
|
||||
guid: url,
|
||||
};
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: '北大未名BBS 全站十大',
|
||||
link: 'https://bbs.pku.edu.cn/v2/hot-topic.php',
|
||||
description: '北大未名BBS 全站热门话题前十名',
|
||||
item,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue