diff --git a/docs/study.md b/docs/study.md index 1a328c98f4..1daf9aab3c 100644 --- a/docs/study.md +++ b/docs/study.md @@ -281,3 +281,9 @@ pageClass: routes ### 最新 + +## 中国人事考试网 + +### 通知公告 + + diff --git a/lib/router.js b/lib/router.js index 92ddfeea50..78dc92b9fc 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2644,6 +2644,9 @@ router.get('/slu/csggxy/:id', require('./routes/universities/slu/csggxy')); router.get('/ruby-china/topics/:type?', require('./routes/ruby-china/topics')); router.get('/ruby-china/jobs', require('./routes/ruby-china/jobs')); +// 中国人事考试网 +router.get('/cpta/notice', require('./routes/cpta/notice')); + // 广告网 router.get('/adquan/:type?', require('./routes/adquan/index')); diff --git a/lib/routes/cpta/notice.js b/lib/routes/cpta/notice.js new file mode 100644 index 0000000000..86aeeedce8 --- /dev/null +++ b/lib/routes/cpta/notice.js @@ -0,0 +1,37 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +module.exports = async (ctx) => { + const link = `http://www.cpta.com.cn/GB/360339/index.html`; + const response = await got({ method: 'get', url: link, responseType: 'buffer' }); + + const $ = cheerio.load(iconv.decode(response.data, 'gbk')); + const list = $('ul.list_14 li') + .map((_, item) => { + item = $(item).find('a'); + return { + title: item.text(), + link: url.resolve(`http://www.cpta.com.cn/`, item.attr('href')), + }; + }) + .get(); + + ctx.state.data = { + title: '中国人事考试网 - 通知公告', + link: link, + item: await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ method: 'get', url: item.link, responseType: 'buffer' }); + const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk')); + item.description = content('div.text').html(); + item.pubDate = new Date(content('#p_publishtime').text().replace(/[年|月]/g, '-').replace(/日/g, ' ') + ' GMT+8').toUTCString(); + return item; + }) + ) + ), + }; +};