diff --git a/docs/reading.md b/docs/reading.md index 20a471c7bc..32cbd8eeef 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -259,3 +259,15 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 ### 主页 + +## 生物谷 + +### 所有栏目 + + + +具体栏目编号,去网站上看标签 + +| 网址 | 对应路由 | +| -------- | -------- | +| http://news.bioon.com/biology | /shengwugu/biology | diff --git a/lib/router.js b/lib/router.js index ddcb92c864..f26d967853 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/shengwugu/index.js b/lib/routes/shengwugu/index.js new file mode 100644 index 0000000000..2545dca2d1 --- /dev/null +++ b/lib/routes/shengwugu/index.js @@ -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, + }; +};