From dfcf2ccbded7281ba2441c971fae19a9a542cfb0 Mon Sep 17 00:00:00 2001 From: SunShinenny Date: Thu, 2 Apr 2020 21:04:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0CET=E5=9B=9B=E5=85=AD?= =?UTF-8?q?=E7=BA=A7=E8=80=83=E8=AF=95=E5=8A=A8=E6=80=81=20(#4339)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 29 +++++++++++ lib/router.js | 3 ++ lib/routes/neea/index.js | 105 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 lib/routes/neea/index.js diff --git a/docs/study.md b/docs/study.md index afaa9d86b9..7ad3e3c274 100644 --- a/docs/study.md +++ b/docs/study.md @@ -40,6 +40,35 @@ pageClass: routes +## NEEA 中国教育考试网 + +### 国家教育考试 + + + +| `:type` | 类别名称 | +| -------- | ------------------ | +| gaokao | 普通高考 | +| chengkao | 成人高考 | +| yankao | 研究生考试 | +| zikao | 自学考试 | +| ntce | 中小学教师资格考试 | + +### 社会证书考试 + + + +| `:type` | 类别名称 | +| ------- | ----------------------------- | +| cet | 全国四六级(CET) | +| ncre | 全国计算机等级考试(NCRE) | +| nit | 全国计算机应用水平考试(NIT) | +| pets | 全国英语等级考试 (PETS) | +| wsk | 全国外语水平考试 (WSK) | +| ccpt | 书画等级考试 (CCPT) | +| wsk | 全国外语水平考试 (WSK) | +| mets | 医护英语水平考试 (METS) | + ## X-MOL 平台 ### 新闻 diff --git a/lib/router.js b/lib/router.js index 8763366fa6..15df59f6a5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2385,6 +2385,9 @@ router.get('/csc/notice/:type?', require('./routes/csc/notice')); // LearnKu router.get('/learnku/:community/:category?', require('./routes/learnku/topic')); +// NEEA +router.get('/neea/:type', require('./routes/neea')); + // 中国农业大学 router.get('/cauyjs', require('./routes/universities/cauyjs/cauyjs')); diff --git a/lib/routes/neea/index.js b/lib/routes/neea/index.js new file mode 100644 index 0000000000..451c70bd4d --- /dev/null +++ b/lib/routes/neea/index.js @@ -0,0 +1,105 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +async function load(link, ctx) { + return await ctx.cache.tryGet(link, async () => { + // 开始加载页面 + const response = await got.get(link); + const $ = cheerio.load(response.data); + // 获取标题 + const title = $('#Content1 > div > ul > li > h1').text(); + // 获取正文内容 + const introduce = $('#ReportIDtext').html(); + + return { + title: title, + description: introduce, + link: link, + }; + }); +} + +module.exports = async (ctx) => { + const type = ctx.params.type; + const host = `http://${type}.neea.edu.cn${typeDic[`${type}`].url}`; + const response = await got({ + method: 'get', + url: host, + }); + const data = response.data; + + const $ = cheerio.load(data); + const list = $(`#ReportIDname > a`).get(); + + const process = await Promise.all( + list.map(async (item) => { + const itemUrl = `http://${type}.neea.edu.cn` + $(item).attr('href'); + const single = { + title: $(item).text(), + link: itemUrl, + guid: itemUrl, + }; + const other = await load(String(itemUrl), ctx); + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + ctx.state.data = { + title: `${typeDic[`${type}`].title}动态`, + link: host, + description: `${typeDic[`${type}`].title}动态 `, + item: process, + }; +}; + +const typeDic = { + // 国家教育考试 + gaokao: { + url: '/html1/category/1507/1945-1.htm', + title: '普通高考', + }, + chengkao: { + url: '/html1/category/1507/1960-1.htm', + title: '成人高考', + }, + yankao: { + url: '/html1/category/1507/2005-1.htm', + title: '研究生考试', + }, + zikao: { + url: '/html1/category/1508/1403-1.htm', + title: '自学考试', + }, + ntce: { + url: '/html1/category/1507/1148-1.htm', + title: '中小学教师资格考试', + }, + // 社会证书考试 + cet: { + url: '/html1/category/16093/1124-1.htm', + title: '全国四六级(CET)', + }, + ncre: { + url: '/html1/category/1507/872-1.htm', + title: '全国计算机等级考试(NCRE)', + }, + nit: { + url: '/html1/category/1507/1630-1.htm', + title: '全国计算机应用水平考试(NIT)', + }, + + pets: { + url: '/html1/category/1507/1570-1.htm', + title: '全国英语等级考试 (PETS)', + }, + wsk: { + url: '/html1/category/1507/1646-1.htm', + title: '全国外语水平考试 (WSK)', + }, + ccpt: { + url: '/html1/category/1507/2035-1.htm', + title: '书画等级考试 (CCPT)', + }, + mets: { + url: '/html1/category/1507/2065-1.htm', + title: '医护英语水平考试 (METS)', + }, +};