mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 22:19:40 +08:00
feat: 增加生物谷 (#4862)
This commit is contained in:
@@ -259,3 +259,15 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5
|
||||
### 主页
|
||||
|
||||
<Route author="kt286" example="/zreading" path="/zreading" />
|
||||
|
||||
## 生物谷
|
||||
|
||||
### 所有栏目
|
||||
|
||||
<Route author="xfangbao" example="/shengwugu/biology" path="/shengwugu/:uid/" :paramsDesc="['分栏代码, 可在 URL 找到']" />
|
||||
|
||||
具体栏目编号,去网站上看标签
|
||||
|
||||
| 网址 | 对应路由 |
|
||||
| -------- | -------- |
|
||||
| http://news.bioon.com/biology | /shengwugu/biology |
|
||||
|
||||
@@ -2772,6 +2772,9 @@ router.get('/zhutix/latest', require('./routes/zhutix/latest'));
|
||||
// arXiv
|
||||
router.get('/arxiv/:query', require('./routes/arxiv/query'));
|
||||
|
||||
// 生物谷
|
||||
router.get('/shengwugu/:uid?', require('./routes/shengwugu/index'));
|
||||
|
||||
// 环球律师事务所文章
|
||||
router.get('/law/hq', require('./routes/law/hq'));
|
||||
|
||||
|
||||
41
lib/routes/shengwugu/index.js
Normal file
41
lib/routes/shengwugu/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = `http://news.bioon.com/${ctx.params.uid}`;
|
||||
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const list = $('.cntx').get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.slice(0, 3).map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('.cntx h4 a').text();
|
||||
const partial = $('.cntx h4 a').attr('href');
|
||||
const address = partial;
|
||||
const time = $('.fl huise').text();
|
||||
const cache = await ctx.cache.get(address);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await got.get(address);
|
||||
const get = cheerio.load(res.data);
|
||||
const contents = get('.text3').html();
|
||||
const single = {
|
||||
title,
|
||||
pubDate: time,
|
||||
description: contents,
|
||||
link: address,
|
||||
guid: address,
|
||||
};
|
||||
ctx.cache.set(address, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user