diff --git a/docs/government.md b/docs/government.md index 6c61fd2e1b..57aa89b069 100644 --- a/docs/government.md +++ b/docs/government.md @@ -28,6 +28,12 @@ pageClass: routes +## 国家税务总局 + +### 最新文件 + + + ## 国家新闻出版广电总局 ### 游戏审批结果 diff --git a/lib/router.js b/lib/router.js index f0ae6b1504..e37ab4290e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2812,4 +2812,7 @@ router.get('/gov/caict/bps', require('./routes/gov/caict/bps')); router.get('/gov/caict/qwsj', require('./routes/gov/caict/qwsj')); router.get('/gov/caict/caictgd', require('./routes/gov/caict/caictgd')); +// 国家税务总局 +router.get('/gov/chinatax/latest', require('./routes/gov/chinatax/latest')); + module.exports = router; diff --git a/lib/routes/gov/chinatax/latest.js b/lib/routes/gov/chinatax/latest.js new file mode 100644 index 0000000000..3e5dd70cb8 --- /dev/null +++ b/lib/routes/gov/chinatax/latest.js @@ -0,0 +1,43 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const link = `http://www.chinatax.gov.cn/chinatax/n810341/n810755/index.html`; + + const response = await got({ + method: 'get', + url: link, + }); + const $ = cheerio.load(response.data); + const list = $('ul.list.whlist li') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: url.resolve(`http://www.chinatax.gov.cn`, a.attr('href')), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + item.pubDate = content('meta[name="PubDate"]').attr('content'); + item.description = content('#fontzoom').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '国家税务总局 - 最新文件', + link: link, + item: items, + }; +};