/
latest.ts
74 lines (70 loc) · 2.09 KB
/
latest.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';
export const route: Route = {
path: '/chinatax/latest',
categories: ['government'],
example: '/gov/chinatax/latest',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.chinatax.gov.cn/*'],
},
],
name: '最新文件',
maintainers: ['nczitzk', 'fuzy112'],
handler,
url: 'www.chinatax.gov.cn/*',
};
async function handler() {
const link = `http://www.chinatax.gov.cn/chinatax/n810341/n810755/index.html`;
const response = await got({
method: 'get',
url: link,
});
const $ = load(response.data);
const list = $('ul.list.whlist li')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: new URL(a.attr('href'), `http://www.chinatax.gov.cn`).toString(),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
try {
const res = await got({ method: 'get', url: item.link });
const content = load(res.data);
item.pubDate = content('meta[name="PubDate"]').attr('content');
item.description = content('#fontzoom').html();
return item;
} catch (error) {
if (error.name === 'HTTPError' || error.name === 'FetchError') {
item.description = error.message;
return item;
}
throw error;
}
})
)
);
return {
title: '国家税务总局 - 最新文件',
link,
item: items,
};
}