/
bkjw.ts
71 lines (69 loc) 路 2.07 KB
/
bkjw.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
const xmut = 'https://jwc.xmut.edu.cn';
export const route: Route = {
path: '/jwc/bkjw/:category?',
name: 'Unknown',
maintainers: [],
handler,
};
async function handler(ctx) {
const { category = 'jwxt' } = ctx.req.param();
const url = `${xmut}/index/tzgg/${category}.htm`;
const res = await got(url, {
headers: {
referer: xmut,
},
https: {
rejectUnauthorized: false,
},
});
const $ = load(res.data);
const itemsArray = $('#result_list table tbody tr')
.map((index, row) => {
const res = $('td', row).eq(0);
const resDate = $('td', row).eq(1);
const resLink = $('a', res).attr('href');
let link;
if (resLink.startsWith('../../')) {
const parsedUrl = new URL(resLink, xmut);
link = parsedUrl.href;
} else {
link = resLink;
}
const title = $('a', res).attr('title');
const pubDate = parseDate(resDate.text().trim());
return {
title,
link,
pubDate,
};
})
.get();
const items = await Promise.all(
itemsArray.map((item) =>
cache.tryGet(item.link, async () => {
const res = await got(item.link, {
headers: {
referer: xmut,
},
https: {
rejectUnauthorized: false,
},
});
const $item = load(res.data);
const content = $item('table #result #content form div #vsb_content_6').html();
item.description = content;
return item;
})
)
);
return {
title: $('title').text(),
link: url,
item: items,
};
}