File size: 1,000 Bytes
ec675f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
p="crawl-full.ts"

s=open(p).read()

insert = r'''
const statistics = await page.evaluate(() => {

  const text = document.body.innerText;

  const patterns = [
    /\d+(?:,\d{3})*(?:\.\d+)?\+?/g,
    /\$[\d,.]+[TBMK]?/g,
    /\d+(?:\.\d+)?%/g,
    /\d+\s*(?:countries|users|customers|requests|transactions|million|billion|trillion)/gi
  ];

  const found = new Set<string>();

  for (const pattern of patterns) {
    const matches = text.match(pattern) || [];

    for (const item of matches) {

      const value = item.trim();

      if (
        value.length > 1 &&
        value.length < 40
      ) {
        found.add(value);
      }
    }
  }

  return Array.from(found).slice(0,100);

});
'''

if "const statistics" not in s:

    s=s.replace(
        "const vp = page.viewportSize();",
        insert + "\nconst vp = page.viewportSize();"
    )


s=s.replace(
    "design,\n        text:",
    "design,\n        statistics,\n        text:"
)

open(p,"w").write(s)

print("statistics added")