-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtimetable.js
More file actions
52 lines (37 loc) · 1.44 KB
/
timetable.js
File metadata and controls
52 lines (37 loc) · 1.44 KB
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 express = require('express');
const { Builder, Capabilities, By, until } = require('selenium-webdriver');
const app = express();
const port = 3001;
app.get('/', async (request, response) => {
// Web Scraping Code here
try {
const data = await timetable();
response.status(200).json(data);
} catch (error) {
response.status(500).json({
message: 'Server error occurred',
});
}
});
async function timetable() {
let caps = new Capabilities();
caps.setPageLoadStrategy("eager"); //capabilities : for speed up
driver = await new Builder().withCapabilities(caps).forBrowser('chrome').build();
await driver.get('https://everytime.kr/login');
//input id, pwd.
await driver.findElement(By.css('[name="userid"]')).sendKeys("summer2788");
await driver.findElement(By.css('[name="password"]')).sendKeys("whddms123!");
await driver.findElement(By.css('[type="submit"]')).click();
//my time table
await driver.get("https://everytime.kr/timetable");
//check if time table is fully loaded.
await driver.wait(until.elementLocated(By.className('wrap')), 30000, 'Timed out after 30 seconds', 5000);
//get timetable
let elements = await driver.findElements(By.className('wrap'));
for (let e of elements) {
console.log(await e.getText());
}
};
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});