-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
38 lines (32 loc) · 942 Bytes
/
scraper.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
const got = require('got');
const cheerio = require('cheerio');
const ObjectsToCsv = require('objects-to-csv');
const parser = require('./parser');
const cliProgress = require('cli-progress');
/**
* Sleep for a period of time
* @param {int} miliseconds
*/
async function sleep(miliseconds) {
return new Promise( (resolve) => setTimeout(resolve, miliseconds));
}
(async () => {
try {
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
bar.start(195, 0);
for (let i = 1; i < 196; i++) {
bar.increment();
const response = await got(`https://apps.shopify.com/browse/all?page=${i}`);
const $ = cheerio.load(response.body);
const data = parser($.html());
const csv = new ObjectsToCsv(data);
await csv.toDisk('data.csv', {
append: true,
});
await sleep(1000);
}
process.exit();
} catch (error) {
console.log(error);
}
})();