-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
41 lines (33 loc) · 1.01 KB
/
main.js
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
/*
* @Author: John Trump
* @Date: 2020-12-09 19:42:28
* @LastEditors: John Trump
* @LastEditTime: 2020-12-11 18:02:37
*/
const cheerio = require("cheerio");
const axios = require("axios").default;
const { writeToJSON, fetchImage } = require("./utils");
const { parse_clfjyimg } = require("./parser");
const { ocrImage } = require("./ocr");
const BASEURL = "http://fdc.zfj.xm.gov.cn/";
/** 入口 */
async function main() {
/* fetch html */
const { data: html } = await axios.get(BASEURL);
const promises = [];
const $ = cheerio.load(html);
/* fetch images[] */
$(".imgcontainer img").each(function(i) {
const src = $(this).attr("src");
promises.push(fetchImage(`${src}`, BASEURL));
});
/* fetch image data */
const results = await Promise.all(promises);
const clfjyimg = await ocrImage(results[2]);
const parsed_clfjyimg = parse_clfjyimg(clfjyimg);
/* write to file */
await writeToJSON(parsed_clfjyimg);
console.log('write success', new Date());
}
main();
// module.exports = main;