feat: add 国家税务总局税收政策最新文件 (#4902)

This commit is contained in:
Ethan Shen
2020-06-07 22:36:00 +08:00
committed by GitHub
parent 4b12e0ac19
commit 10a7234aa5
3 changed files with 52 additions and 0 deletions

View File

@@ -28,6 +28,12 @@ pageClass: routes
</Route> </Route>
## 国家税务总局
### 最新文件
<Route author="nczitzk" example="/gov/chinatax/latest" path="/gov/chinatax/latest"/>
## 国家新闻出版广电总局 ## 国家新闻出版广电总局
### 游戏审批结果 ### 游戏审批结果

View File

@@ -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/qwsj', require('./routes/gov/caict/qwsj'));
router.get('/gov/caict/caictgd', require('./routes/gov/caict/caictgd')); router.get('/gov/caict/caictgd', require('./routes/gov/caict/caictgd'));
// 国家税务总局
router.get('/gov/chinatax/latest', require('./routes/gov/chinatax/latest'));
module.exports = router; module.exports = router;

View File

@@ -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,
};
};