fix(route): thu-career (#7894)

Co-authored-by: SettingDust <settingdust@gmail.com>
This commit is contained in:
DylanXie123 2021-08-12 14:34:42 +08:00 committed by GitHub
parent 311cd9a15d
commit 7d171a2887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 19 deletions

View File

@ -1494,7 +1494,7 @@ type 列表:
### 清华大学招聘信息
<Route author="Halcao" example="/thu/career" path="/thu/career" />
<Route author="Halcao DylanXie123" example="/thu/career" path="/thu/career" />
## 山东大学

View File

@ -1,13 +1,33 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const resolve_url = require('url').resolve;
const { parseDate } = require('@/utils/parse-date');
const base_url = 'https://career.cic.tsinghua.edu.cn/';
const route = 'xsglxt/f/jyxt/anony/xxfb';
module.exports = async (ctx) => {
const page = 1;
const list = await fetchPage(1);
const route = 'xsglxt/f/jyxt/anony/xxfb';
const title = '招聘信息';
ctx.state.data = {
title: '清华大学 - ' + title,
link: base_url + route,
description: '清华大学学生职业发展指导中心 - ' + title,
item: await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got.get(item.link);
const content = cheerio.load(res.data);
item.description = content("div.sideleft.left, div.content.teacher").html();
return item;
})
)
),
};
};
async function fetchPage(page) {
const response = await got({
method: 'post',
url: base_url + route,
@ -23,18 +43,16 @@ module.exports = async (ctx) => {
});
const $ = cheerio.load(response.data);
const title = '招聘信息';
ctx.state.data = {
title: '清华大学 - ' + title,
link: base_url,
description: '清华大学学生职业发展指导中心 - ' + title,
item: $('#ts_div .list li')
.map((_, elem) => ({
link: resolve_url(base_url, $('a', elem).attr('ahref')),
title: $('a', elem).text(),
pubDate: new Date($('span', elem).text()).toUTCString(),
}))
.get(),
};
};
return $('#ts_div .list li')
.map((_, item) => {
item = $(item);
const a = item.find('a');
const date = parseDate(item.find('span').text());
return {
title: a.text(),
link: new URL(a.attr('ahref'), base_url),
pubDate: date,
};
})
.get();
}