mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
add 半月谈 (#1799)
This commit is contained in:
@@ -3227,3 +3227,7 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
<route name="观点" author="LogicJake" example="/people/opinion/223228" path="/people/opinion/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>
|
||||
|
||||
</route>
|
||||
|
||||
### 半月谈
|
||||
|
||||
<route name="板块" author="LogicJake" example="/banyuetan/jicengzhili" path="/banyuetan/:name" :paramsDesc="['板块名称,可在 URL 中找到']"/>
|
||||
|
||||
@@ -1174,6 +1174,9 @@ router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts'));
|
||||
router.get('/zjgsu/gsgg', require('./routes/universities/zjgsu/gsgg/scripts'));
|
||||
router.get('/zjgsu/xszq', require('./routes/universities/zjgsu/xszq/scripts'));
|
||||
|
||||
// 半月谈
|
||||
router.get('/banyuetan/:name', require('./routes/banyuetan'));
|
||||
|
||||
// 人民日报
|
||||
router.get('/people/opinion/:id', require('./routes/people/opinion'));
|
||||
|
||||
|
||||
64
lib/routes/banyuetan/index.js
Normal file
64
lib/routes/banyuetan/index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const name = ctx.params.name;
|
||||
|
||||
const link = `http://www.banyuetan.org/byt/${name}/index.html`;
|
||||
const response = await axios.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('ul.clearFix li')
|
||||
.slice(0, 10)
|
||||
.map(function() {
|
||||
const info = {
|
||||
title: $(this)
|
||||
.find('h3 a')
|
||||
.text(),
|
||||
link: $(this)
|
||||
.find('h3 a')
|
||||
.attr('href'),
|
||||
date: $(this)
|
||||
.find('span.tag3')
|
||||
.text(),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (info) => {
|
||||
const title = info.title;
|
||||
const date = info.date;
|
||||
const itemUrl = info.link;
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios.get(itemUrl);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const description = $('div.detail_content')
|
||||
.html()
|
||||
.trim();
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
description: description,
|
||||
pubDate: new Date(date).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name}-半月谈`,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user