Files
RSSHub/lib/v2/szu/yz/index.js
T
Tony 8699b4c9d3 fix(route): fix namespace mess from #4283 (#12353)
* refactor: fix scut namespace

* refactor: fix gzhu namespace

* refactor: fix scnu namespace

* refactor: fix hust namespace

* refactor: fix ccnu namespace

* refactor: fix sustech namespace

* refactor: fix szu namespace

remove `/szuyjs` since it's a duplicate of `/szu/yz/:type?`

* refactor: fix tongji namespace

* refactor: fix ocu namespace

* refactor: fix upc namespace

* refactor: fix ucas namespace

* refactor: fix cas namespace

* refactor: fix cau namespace

* refactor: remove `/cucyjs` since `/cuc/yz` existed well before that

* refactor: fix bit namespace

* refactor: fix **undocumented** scau namespace

* fix: typo

* fix: code scan
2023-04-20 09:32:13 +08:00

52 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const util = require('./utils');
const map = new Map([
[1, { title: '硕士招生 - 深圳大学研究生招生网' }],
[2, { title: '博士招生 - 深圳大学研究生招生网' }],
]);
module.exports = async (ctx) => {
let type = parseInt(ctx.params.type);
const struct = {
1: {
selector: {
list: '.list',
item: 'li',
content: '#vsb_content',
},
url: 'https://yz.szu.edu.cn/sszs/gg.htm',
},
2: {
selector: {
list: '.list',
item: 'li',
content: '#vsb_content, #vsb_content_2',
},
url: 'https://yz.szu.edu.cn/bszs/gg.htm',
},
};
if (type !== 1 && type !== 2) {
// fallback to default
type = 1;
}
const url = struct[type].url;
const response = await got(url);
const data = response.data;
const $ = cheerio.load(data);
const list = $(struct[type].selector.list).find(struct[type].selector.item).toArray();
const name = $('title').text();
const result = await util.ProcessFeed(list, ctx.cache, struct[type]);
ctx.state.data = {
title: map.get(type).title,
link: url,
description: name,
item: result,
};
};