feat: add 中国人大网 (#5772)

Co-authored-by: Tecent Cloud <work01@233yeee.com>
This commit is contained in:
233yeee
2020-10-03 00:17:52 +01:00
committed by GitHub
co-authored by Tecent Cloud
parent daeace687d
commit 7565a7d2d8
3 changed files with 55 additions and 0 deletions
+10
View File
@@ -133,6 +133,16 @@ pageClass: routes
<Route author="Yoge-Code" example="/gov/cnca/zxtz" path="/gov/cnca/zxtz"/>
## 中国人大网
<Route author="233yeee" example="/npc/c183" path="/npc/:caty" :paramsDesc="['分类名,支持形如`http://www.npc.gov.cn/npc/*/list.shtml`的网站,传入 npc 之后的参数']">
| 立法 | 监督 | 代表 | 理论 | 权威发布 | 滚动新闻 |
| ---- | ---- | ---- | ---- | -------- | -------- |
| c183 | c184 | c185 | c189 | c12435 | c10134 |
</Route>
## 中国信息通信研究院
### 白皮书
+3
View File
@@ -3269,4 +3269,7 @@ router.get('/nobelprize/:caty?', require('./routes/nobelprize/index'));
// 中華民國國防部
router.get('/gov/taiwan/mnd', require('./routes/gov/taiwan/mnd'));
// 中国人大网
router.get('/npc/:caty', require('./routes/npc/index'));
module.exports = router;
+42
View File
@@ -0,0 +1,42 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { caty } = ctx.params;
// 主页
const response = await got(`http://www.npc.gov.cn/npc/${caty}/list.shtml`);
const data = response.body;
const $ = cheerio.load(data, { decodeEntities: false });
const title = $('title').text();
// 获取每条的链接
const links = $('.clist a')
.map((index, item) => [$(item).attr('href')])
.get();
// 获取标题、日期
const list = await Promise.all(
links.map(async (link) => {
const response = await got(`http://www.npc.gov.cn${link}`);
const data = response.body;
const $ = cheerio.load(data, { decodeEntities: false });
const title = $('title').text().replace('_中国人大网', '');
const time = $('span.fr').text();
const description = $('#Zoom p')
.map((index, item) => $.html(item))
.get()
.join('');
return Promise.resolve([title, link, time, description]);
})
);
// 整合
ctx.state.data = {
title: title,
link: `http://www.npc.gov.cn/npc/${caty}/list.shtml`,
description: title,
item: list.map((item) => ({
title: item[0],
link: `http://www.npc.gov.cn${item[1]}`,
pubDate: new Date(item[2].substr(0, 4), parseInt(item[2].substr(5, 2)) - 1, item[2].substr(8, 2), item[2].substr(12, 2), item[2].substr(15, 2), item[2].substr(18, 2)).toUTCString(),
description: item[3],
})),
};
};