-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (36 loc) · 1.43 KB
/
app.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
const puppeteer = require('puppeteer');
(async()=>{
const browser = await puppeteer.launch({
ignoreHTTPSErrors: false,
headless: false,
devtools: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
})
page = await browser.newPage();
await page.goto('https://www.typing.com/student/typing-test/1-minute')
.then(()=>console.log("[👍] Page OK"))
.catch((e)=>console.log('!!! Goto Fail page'))
// Wait for selector
await page.waitForSelector('button.js-continue-button',{timeout: 5000})
.then(async()=>{
await page.click('button.js-continue-button')
console.log('[👍] Continue ok')
})
await page.waitForSelector('.letter',{timeout: 0})
.then(()=>console.log('[👍] Selector ok'))
let rows = await page.evaluate(
()=> Array.from(window.document.querySelectorAll('.letter'))
.map((row)=>{
return row.innerHTML
}).join('')
)
rows = rows.split(';')
rows = rows.join(' ')
rows = rows.split(' ')
rows = rows.join('')
console.log('rows')
// Filter data
console.log("Total file scraped "+rows.length)
console.log(rows);
await page.type('.letter',rows,{delay:1.5})
})()