-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (30 loc) · 978 Bytes
/
index.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
'use strict'
const utils = require('./utils.js')
const settings = require('./settings.js');
(async () => {
// Start a timer.
console.time('Scrape duration')
if (settings.json) {
// Write the file "header"
await utils.addToEndOfFile(settings.domainsJsonFilePath, '{"domains":[')
}
if (settings.csv) {
// Write the file "header"
await utils.addToEndOfFile(settings.domainsCsvFilePath, settings.csvHeaderChema)
}
if (!settings.json && !settings.csv) {
console.log('Stopping the scrape as you\'ve disabled all available output methods')
// Stop the timer.
console.timeEnd('Scrape duration')
// Early exit
return
}
// Start recursive fetching & writing to files.
await utils.fetchAndWriteDomainsToFile(settings.pagingStartUrl)
// End the json file properly.
if (settings.json) {
await utils.addToEndOfFile(settings.domainsJsonFilePath, ']}')
}
// Stop the timer.
console.timeEnd('Scrape duration')
})()