fix(route): 对外经济贸易大学人力资源处 (#8621)

This commit is contained in:
Ethan Shen 2022-01-23 00:11:49 +08:00 committed by GitHub
parent b3b51cbc5d
commit b04a5b8ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 13 deletions

View File

@ -16,30 +16,34 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('.lawul, .longul')
let items = $('.lawul, .longul')
.find('li a')
.map((_, item) => {
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('p').text(),
link: `${currentUrl}/${item.attr('href')}`,
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
const content = cheerio.load(detailResponse.data);
item.description = content('.gp-article').html();
item.pubDate = parseDate(content('#shareTitle').next().text().replace('时间:', ''));
item.description = content('.gp-article').html();
item.pubDate = parseDate(content('#shareTitle').next().text().replace('时间:', ''));
} catch (err) {
item.description = 'Not Found';
}
return item;
})