From 7565a7d2d872fe89ece5cd682468ac3e44fe8545 Mon Sep 17 00:00:00 2001 From: 233yeee <71996495+233yeee@users.noreply.github.com> Date: Sat, 3 Oct 2020 07:17:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=AD=E5=9B=BD=E4=BA=BA?= =?UTF-8?q?=E5=A4=A7=E7=BD=91=20(#5772)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tecent Cloud --- docs/government.md | 10 ++++++++++ lib/router.js | 3 +++ lib/routes/npc/index.js | 42 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/npc/index.js diff --git a/docs/government.md b/docs/government.md index fdf5ca977b..39315111bd 100644 --- a/docs/government.md +++ b/docs/government.md @@ -133,6 +133,16 @@ pageClass: routes +## 中国人大网 + + + +| 立法 | 监督 | 代表 | 理论 | 权威发布 | 滚动新闻 | +| ---- | ---- | ---- | ---- | -------- | -------- | +| c183 | c184 | c185 | c189 | c12435 | c10134 | + + + ## 中国信息通信研究院 ### 白皮书 diff --git a/lib/router.js b/lib/router.js index 89f567a781..8be0af7959 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/npc/index.js b/lib/routes/npc/index.js new file mode 100644 index 0000000000..4fcb836551 --- /dev/null +++ b/lib/routes/npc/index.js @@ -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], + })), + }; +};