Files
RSSHub/lib/v2/neea/index.js
T
Tony 6d901cb7dc style(eslint): add eslint-unicorn (#14257)
* style: add eslint-unicorn

* style: fix unicorn/no-useless-spread

* style: fix unicorn/no-useless-promise-resolve-reject

* style: fix unicorn/no-for-loop

* fix: codeql bad HTML filtering regexp

* fix: codeql incomplete replace

* fix: unicorn/no-abusive-eslint-disable

* style: fix unicorn/no-new-array

* style: fix unicorn/no-typeof-undefined

* style: fix unicorn/no-zero-fractions

* style: fix unicorn/no-empty-file

* style: fix unicorn/prefer-date-now

* revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js

* style: fix unicorn/prefer-array-find

* style: fix unicorn/prefer-array-flat

* style: fix unicorn/prefer-array-flat-map

* style: fix unicorn/prefer-at

* style: fix unicorn/prefer-string-starts-ends-with

* style: fix unicorn/prefer-includes

* fix: codeql URL substring sanitization

* style: fix unicorn/prefer-optional-catch-binding

* style: fix unicorn/catch-error-name

* style: fix unicorn/escape-case

* style: fix unicorn/prefer-native-coercion-functions

* style: fix unicorn/prefer-regexp-test

* style: fix unicorn/require-array-join-separator

* style: fix unicorn/prefer-math-trunc

* style: fix unicorn/prefer-negative-index

* style: fix unicorn/prefer-dom-node-dataset

* style: fix unicorn/prefer-dom-node-text-content

* style: fix unicorn/prefer-query-selector

* style: fix unicorn/no-array-for-each

* style: fix unicorn/no-negated-condition

* style: fix unicorn/prefer-add-event-listener

* style: fix unicorn/import-style

* style: fix prefer-regex-literals

* style: disable unicorn/no-useless-switch-case

* style: disable unicorn/text-encoding-identifier-case

* style: fix unicorn/prefer-set-has

* style: fix unicorn/prefer-spread

* revert: auto fix on lib/routes/universities/ynnu/edu/base64.js

* style: fix unicorn/no-useless-undefined

* style: fix unicorn/no-array-push-push

* style: fix unicorn/no-useless-undefined again

* style: fix unicorn/no-lonely-if

* style: fix unicorn/prefer-reflect-apply

* style: fix unicorn/switch-case-braces

* style: fix unicorn/prefer-switch

* style: fix unicorn/prefer-array-some

* fix: deepscan UNUSED_VAR_ASSIGN

* style: fix unicorn/prefer-ternary

* fix: follow-up of unicorn/prefer-ternary

* revert: auto fix of unicorn/prefer-string-slice for substring()

* style: disable unicorn/prefer-string-slice

fix: auto fix slice over deprecated substr

* style: fix unicorn/throw-new-error

* style: fix unicorn/filename-case

* test: fix dateParser renaming

* style: fix unicorn/better-regex

* style: fix unicorn/prefer-string-replace-all

* fix(deps): add sanitize-html

* style: fix no-prototype-builtins

* style: fix unicorn/consistent-destructuring

* style: fix unicorn/consistent-function-scoping

* style: fix unicorn/prefer-regexp-test

* style: fix unicorn/prefer-logical-operator-over-ternary

* style: fix unicorn/no-array-callback-reference

* style: add prefer-object-has-own

* style: warn unicorn/no-empty-file

* style: fix unicorn/prefer-number-properties

* style: fix no-useless-undefined again

* style: fix unicorn/numeric-separators-style

* style: disable unicorn/no-array-callback-reference

false postive with cheerio
2024-01-18 20:43:40 +08:00

111 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const cheerio = require('cheerio');
function load(link, ctx) {
return 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,
description: introduce,
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`).parent().parent().get();
const process = await Promise.all(
list.map(async (item) => {
const ReportIDname = $(item).find('#ReportIDname > a');
const ReportIDIssueTime = $(item).find('#ReportIDIssueTime');
const itemUrl = `http://${type}.neea.edu.cn` + $(ReportIDname).attr('href');
let time = new Date(ReportIDIssueTime.text()).getTime();
time += new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000; // beijing timezone
const single = {
title: $(ReportIDname).text(),
link: itemUrl,
guid: itemUrl,
pubDate: new Date(time).toUTCString(),
};
const other = await load(String(itemUrl), ctx);
return Object.assign({}, single, other);
})
);
ctx.state.data = {
title: `${typeDic[String(type)].title}动态`,
link: host,
description: `${typeDic[String(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)',
},
};