/
wenjian.ts
74 lines (69 loc) · 2.17 KB
/
wenjian.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
72
73
74
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export const route: Route = {
path: '/zhengce/wenjian/:pcodeJiguan?',
categories: ['government'],
example: '/gov/zhengce/wenjian',
parameters: { pcodeJiguan: '文种分类。国令、国发、国函、国发明电、国办发、国办函、国办发明电、其他' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.gov.cn/'],
target: '/zhengce/wenjian',
},
],
name: '最新文件',
maintainers: ['ciaranchen'],
handler,
url: 'www.gov.cn/',
};
async function handler(ctx) {
const pcodeJiguan = ctx.req.param('pcodeJiguan');
const link = 'http://sousuo.gov.cn/list.htm';
const res = await got(link, {
searchParams: {
n: ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20,
sort: 'pubtime',
t: 'paper',
pcodeJiguan: pcodeJiguan ?? '',
},
});
const $ = load(res.data);
const list = $('body > div.dataBox > table > tbody > tr')
.slice(1)
.toArray()
.map((elem) => {
elem = $(elem);
return {
title: elem.find('td:nth-child(2) > a').text(),
link: elem.find('td:nth-child(2) > a').attr('href'),
pubDate: timezone(parseDate(elem.find('td:nth-child(5)').text()), 8),
};
});
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const contentData = await got(item.link);
const $ = load(contentData.data);
item.description = $('#UCAP-CONTENT').html();
return item;
})
)
);
return {
title: '最新文件 - 中国政府网',
link: res.url,
item: items,
};
}