-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (40 loc) · 1.42 KB
/
index.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
const puppeteer = require('puppeteer');
const urlControle = "https://pre.ufcg.edu.br:8443/ControleAcademicoOnline/";
const urlCurriculo = "https://pre.ufcg.edu.br:8443/ControleAcademicoOnline/Controlador?command=AlunoCurriculo";
getCurriculo = async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(urlControle);
const matricula = '';
const senha = '';
await page.type('#login', matricula);
await page.type('#senha', senha);
const form = await page.$('.form-horizontal');
await form.evaluate(form => form.submit());
await page.waitForNavigation({waitUntil: 'load'});
console.log('FOUND!', page.url());
await page.goto(urlCurriculo);
console.log('FOUND!', page.url());
const curriculo = await page.evaluate(() => {
const table = document.querySelectorAll('tr.success');
const getInfoRow = (row) => {
const elements = row.querySelectorAll('td');
const span = elements[2].querySelector('span');
span.parentNode.removeChild(span);
return {cod: elements[1].innerText,
name: elements[2].innerText};
}
const data = [];
table.forEach(element => {
data.push(getInfoRow(element));
});
return data;
})
await browser.close();
return curriculo;
}catch (err){
console.log(err);
}
}
console.log(getCurriculo());