-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
57 lines (39 loc) · 1.55 KB
/
test.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
52
53
54
55
56
57
import puppeteer from "puppeteer"
import fs from "fs"
const waitTillHTMLRendered = async (page, timeout = 30000) => {
if (page == `` || page == null) {
throw error(`Html Page is Not Defined`)
}
const checkDurationMsecs = 1000;
const maxChecks = timeout / checkDurationMsecs;
let lastHTMLSize = 0;
let checkCounts = 1;
let countStableSizeIterations = 0;
const minStableSizeIterations = 3;
while (checkCounts++ <= maxChecks) {
let html = await page.content();
let currentHTMLSize = html.length;
let bodyHTMLSize = await page.evaluate(() => document.body.innerHTML.length);
// console.log('last: ', lastHTMLSize, ' <> curr: ', currentHTMLSize);
if (lastHTMLSize != 0 && currentHTMLSize == lastHTMLSize)
countStableSizeIterations++;
else
countStableSizeIterations = 0; //reset the counter
if (countStableSizeIterations >= minStableSizeIterations) {
// console.log("Page rendered fully..");
break;
}
lastHTMLSize = currentHTMLSize;
await page.waitForTimeout(checkDurationMsecs)
}
};
const list = fs.readFileSync(`./theList.txt`,{encoding:"utf-8"})
const regex = /([a-zA-Z0-9-]+@[a-zA-Z0-9-]+\.[a-zA-Z]+-?(\.[a-zA-Z]+))/g
let clearData
let dataArray = await list.match(regex)
console.log(dataArray.length)
dataArray.forEach((item,index)=>{
dataArray = dataArray.filter(filterItem => filterItem != item)
dataArray.push(item)
})
fs.writeFileSync(`./theList.txt`,dataArray.join(`,`),{encoding:"utf-8"})