-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (53 loc) · 1.92 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
54
55
56
57
58
59
60
const puppeteer = require("puppeteer");
require("dotenv").config();
const username = process.env.E_USERNAME;
const password = process.env.E_PASSWORD;
const showBrowser = true;
const repeat = 100;
const loginUri =
"https://www3.gobiernodecanarias.org/educacion/cau_ce/cas/login?service=https%3A%2F%2Fwww3.gobiernodecanarias.org%2Fmedusa%2Fevagd%2Fgcsur%2Flogin%2Findex.php";
const logoutUri =
"https://www3.gobiernodecanarias.org/educacion/cau_ce/cas/logout?service=https%3A%2F%2Fwww3.gobiernodecanarias.org%2Feducacion%2Fcau_ce%2Fcas%2Flogout";
const coursePageUri =
"https://www3.gobiernodecanarias.org/medusa/evagd/gcsur/course/view.php?id=14493";
const usernameInput = 'input[name="username"]';
const passwordInput = 'input[name="password"]';
const loginButton = 'button[id="btn-login"]';
const courseActivitySelector = ".aalink";
async function getPoints() {
const browser = await puppeteer.launch({ headless: !showBrowser });
const page = await browser.newPage();
await page.setViewport({
width: 1280,
height: 800,
isMobile: false,
});
const gotoUri = (uri) => {
return page.goto(uri, { waitUntil: "networkidle2" });
};
const login = async () => {
await gotoUri(loginUri);
await page.waitForSelector(usernameInput);
await page.waitForTimeout(300);
await page.type(usernameInput, username);
await page.type(passwordInput, password);
await page.click(loginButton);
};
const openActivities = async () => {
await gotoUri(coursePageUri);
await page.waitForTimeout(300);
const activities = await page.$$(courseActivitySelector);
for (let i = 0; i < activities.length; i++) {
await activities[i].click({ button: "middle" });
}
};
await login();
await page.waitForTimeout(300);
await openActivities();
await page.waitForTimeout(100);
await gotoUri(logoutUri);
await browser.close();
}
(async () => {
for (let i = 0; i < repeat; i++) await getPoints();
})();