forked from wechat-article/wechat-article-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_cgi_data.ts
More file actions
28 lines (25 loc) · 903 Bytes
/
parse_cgi_data.ts
File metadata and controls
28 lines (25 loc) · 903 Bytes
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
import { parseCgiDataNew } from '#shared/utils/html';
import { read, samples, write } from './common';
function normalizeOutPath(input: string): string {
const segments = input.split('/');
segments[segments.length - 1] = 'output/parse-' + segments[segments.length - 1];
return segments.join('/').replace(/\.html$/, '.json');
}
async function run() {
for (const group of samples.filter(group => group.hasContent)) {
console.group(group.name);
for (const samplePath of group.samples) {
const html = read(samplePath);
const cgiData = await parseCgiDataNew(html);
if (!cgiData) {
console.warn('提取 window.cgiDataNew 对象失败');
continue;
}
console.log('item_show_type:', cgiData.item_show_type);
write(normalizeOutPath(samplePath), JSON.stringify(cgiData, null, 2));
}
console.groupEnd();
console.log();
}
}
run();