-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrap.js
49 lines (40 loc) · 1.27 KB
/
scrap.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
import pup from 'puppeteer'
const url = 'https://diario.seduc.ro.gov.br/portal/login.php'
const defaultTypingOptions = { visible: true, timeout: 3000 }
const getNormalTable = async (page) => {
let data = await page.evaluate(() => {
const dataObject = {}
const tbody = document.querySelector('#notas tbody')
for (const row of tbody.rows) {
const [keyCell, ...cells] = row.cells
dataObject[keyCell.innerText] = cells.map((a) => a.innerText)
}
return dataObject
})
return data
}
export const getGrades = async () => {
const browser = await pup.launch({
headless: true,
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-sandbox'
]
})
const page = await browser.newPage()
await page.goto(url, { waitFor: 'networkidle2' })
await page.type('#cpf', process.env.CPF, defaultTypingOptions)
await page.type('#senha', process.env.PASSWORD, defaultTypingOptions)
await page.click('button[type="submit"]')
await page.waitForNavigation()
const [element] = await page.$x(
'/html/body/div[3]/fieldset/div/div/div/div[3]/div/div[1]/a'
)
await element.click()
await page.waitForNavigation()
const table = await getNormalTable(page)
await browser.close()
return table
}