-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-file-generator.js
51 lines (37 loc) · 1.12 KB
/
json-file-generator.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
42
43
44
45
46
47
48
49
50
51
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch({
headless: true,
devtools: false,
timeout: 0,
//slowMo: 0 // slow down by 250ms
});
const page = await browser.newPage();
await page.setViewport({
width: 2000,
height: 1080
})
const navigationPromise = page.waitForNavigation()
await page.goto(`https://www.browserling.com/tools/random-json`, { waitUntil: 'networkidle2', timeout: 0 })
await page.evaluate(() => {
$('#random-json-depth').val("8")
});
try {
let folderExist = await fs.exists('./json')
if (!folderExist) {
await fs.mkdir('./json')
}
} catch (e) {
}
for (var i = 0; i < 1000; i++) {
await page.click('#random-json-submit')
let result = await page.evaluate(() => {
return $('#random-json-text').val()
});
console.log('saving', i+1)
await fs.writeFileSync(`./json/${(i+1)}.json`, result)
}
console.log("done")
await browser.close()
})();