Showing
6 changed files
with
100 additions
and
41 deletions
... | @@ -5,6 +5,23 @@ | ... | @@ -5,6 +5,23 @@ |
5 | "version": "0.2.0", | 5 | "version": "0.2.0", |
6 | "configurations": [ | 6 | "configurations": [ |
7 | { | 7 | { |
8 | + "type": "node", | ||
9 | + "request": "launch", | ||
10 | + "name": "Mocha All", | ||
11 | + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | ||
12 | + "args": [ | ||
13 | + "--timeout", | ||
14 | + "999999", | ||
15 | + "--colors", | ||
16 | + "${workspaceFolder}/test" | ||
17 | + ], | ||
18 | + "console": "integratedTerminal", | ||
19 | + "internalConsoleOptions": "neverOpen", | ||
20 | + "skipFiles": [ | ||
21 | + "<node_internals>/**/*.js" | ||
22 | + ] | ||
23 | + }, | ||
24 | + { | ||
8 | "type": "pwa-node", | 25 | "type": "pwa-node", |
9 | "request": "launch", | 26 | "request": "launch", |
10 | "name": "Launch Program", | 27 | "name": "Launch Program", | ... | ... |
... | @@ -40,33 +40,45 @@ ex) | ... | @@ -40,33 +40,45 @@ ex) |
40 | */ | 40 | */ |
41 | 41 | ||
42 | export async function get_schedule(id, pw, target_date) { | 42 | export async function get_schedule(id, pw, target_date) { |
43 | - login(id, pw).then(async driver => { | 43 | + return using_selenium((driver) => { |
44 | - load(driver, target_date) | 44 | + return login(driver, id, pw) |
45 | - .then(it => { | 45 | + .then(() => { |
46 | - console.log(it) | 46 | + return load(driver, target_date) |
47 | - logout(driver) | 47 | + .then((data) => { |
48 | - }) | 48 | + //logout(driver) |
49 | + console.log(data) | ||
50 | + return data | ||
51 | + }) | ||
52 | + }) | ||
49 | }) | 53 | }) |
50 | } | 54 | } |
51 | 55 | ||
52 | -export async function login(id, pw) { | 56 | +export async function using_selenium(next) { |
53 | const option = new firefox.Options() | 57 | const option = new firefox.Options() |
54 | - option.setBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe') | 58 | + option.addArguments("-headless"); |
59 | + | ||
55 | const driver = new selenium.Builder() | 60 | const driver = new selenium.Builder() |
56 | .forBrowser('firefox') | 61 | .forBrowser('firefox') |
57 | .setFirefoxOptions(option) | 62 | .setFirefoxOptions(option) |
58 | .build() | 63 | .build() |
59 | 64 | ||
65 | + next(driver).finally(() => { | ||
66 | + driver.quit() | ||
67 | + }) | ||
68 | +} | ||
69 | + | ||
70 | +export async function login(driver, id, pw) { | ||
71 | + | ||
60 | await driver.get("https://khcanvas.khu.ac.kr/") | 72 | await driver.get("https://khcanvas.khu.ac.kr/") |
61 | 73 | ||
62 | const idInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_id"]')); | 74 | const idInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_id"]')); |
63 | const pwInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_password"]')); | 75 | const pwInput = await driver.findElement(selenium.By.xpath('//*[@id="login_user_password"]')); |
64 | const login_button = await driver.findElement(selenium.By.xpath('//*[@id="form1"]/div/div[3]')); | 76 | const login_button = await driver.findElement(selenium.By.xpath('//*[@id="form1"]/div/div[3]')); |
65 | - | 77 | + |
66 | await idInput.sendKeys(id); | 78 | await idInput.sendKeys(id); |
67 | await pwInput.sendKeys(pw); | 79 | await pwInput.sendKeys(pw); |
68 | await login_button.click(); | 80 | await login_button.click(); |
69 | - | 81 | + |
70 | return driver | 82 | return driver |
71 | } | 83 | } |
72 | 84 | ||
... | @@ -76,7 +88,7 @@ export async function load(driver, until) { | ... | @@ -76,7 +88,7 @@ export async function load(driver, until) { |
76 | await driver.get(`https://khcanvas.khu.ac.kr/api/v1/planner/items?start_date=${start_date}`); | 88 | await driver.get(`https://khcanvas.khu.ac.kr/api/v1/planner/items?start_date=${start_date}`); |
77 | await sleep(1000) | 89 | await sleep(1000) |
78 | await driver.findElement(selenium.By.xpath('/html/body/div/div/nav/ul/li[2]')).click(); | 90 | await driver.findElement(selenium.By.xpath('/html/body/div/div/nav/ul/li[2]')).click(); |
79 | - | 91 | + |
80 | const data = await driver.findElement(selenium.By.xpath('/html/body/div/div/div/div[2]/div/div/div[2]/pre')); | 92 | const data = await driver.findElement(selenium.By.xpath('/html/body/div/div/div/div[2]/div/div/div[2]/pre')); |
81 | const text = JSON.parse((await data.getText()).slice(9)) | 93 | const text = JSON.parse((await data.getText()).slice(9)) |
82 | 94 | ... | ... |
1 | import fs from 'fs/promises' | 1 | import fs from 'fs/promises' |
2 | import { login, load, logout } from './khcanvas.js'; | 2 | import { login, load, logout } from './khcanvas.js'; |
3 | 3 | ||
4 | -fs.readFile("asdffdsa.txt").then(it => { | ||
5 | - const auth = it.toString().split('|') | ||
6 | - login(auth[0], auth[1]).then(async driver => { | ||
7 | - load(driver, new Date()) | ||
8 | - .then(it => { | ||
9 | - console.log(it) | ||
10 | - logout(driver) | ||
11 | - }) | ||
12 | - }).catch(err => { console.log(err) }) | ||
13 | -}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -9,7 +9,7 @@ | ... | @@ -9,7 +9,7 @@ |
9 | "version": "1.0.0", | 9 | "version": "1.0.0", |
10 | "dependencies": { | 10 | "dependencies": { |
11 | "@types/selenium-webdriver": "^4.1.0", | 11 | "@types/selenium-webdriver": "^4.1.0", |
12 | - "eslint": "^8.15.0", | 12 | + "eslint": "^8.16.0", |
13 | "mocha": "^10.0.0", | 13 | "mocha": "^10.0.0", |
14 | "selenium-webdriver": "^4.1.2" | 14 | "selenium-webdriver": "^4.1.2" |
15 | }, | 15 | }, |
... | @@ -18,14 +18,14 @@ | ... | @@ -18,14 +18,14 @@ |
18 | } | 18 | } |
19 | }, | 19 | }, |
20 | "node_modules/@eslint/eslintrc": { | 20 | "node_modules/@eslint/eslintrc": { |
21 | - "version": "1.2.3", | 21 | + "version": "1.3.0", |
22 | - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.3.tgz", | 22 | + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", |
23 | - "integrity": "sha512-uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA==", | 23 | + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", |
24 | "dependencies": { | 24 | "dependencies": { |
25 | "ajv": "^6.12.4", | 25 | "ajv": "^6.12.4", |
26 | "debug": "^4.3.2", | 26 | "debug": "^4.3.2", |
27 | "espree": "^9.3.2", | 27 | "espree": "^9.3.2", |
28 | - "globals": "^13.9.0", | 28 | + "globals": "^13.15.0", |
29 | "ignore": "^5.2.0", | 29 | "ignore": "^5.2.0", |
30 | "import-fresh": "^3.2.1", | 30 | "import-fresh": "^3.2.1", |
31 | "js-yaml": "^4.1.0", | 31 | "js-yaml": "^4.1.0", |
... | @@ -439,11 +439,11 @@ | ... | @@ -439,11 +439,11 @@ |
439 | } | 439 | } |
440 | }, | 440 | }, |
441 | "node_modules/eslint": { | 441 | "node_modules/eslint": { |
442 | - "version": "8.15.0", | 442 | + "version": "8.16.0", |
443 | - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.15.0.tgz", | 443 | + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.16.0.tgz", |
444 | - "integrity": "sha512-GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6SA==", | 444 | + "integrity": "sha512-MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yoA==", |
445 | "dependencies": { | 445 | "dependencies": { |
446 | - "@eslint/eslintrc": "^1.2.3", | 446 | + "@eslint/eslintrc": "^1.3.0", |
447 | "@humanwhocodes/config-array": "^0.9.2", | 447 | "@humanwhocodes/config-array": "^0.9.2", |
448 | "ajv": "^6.10.0", | 448 | "ajv": "^6.10.0", |
449 | "chalk": "^4.0.0", | 449 | "chalk": "^4.0.0", |
... | @@ -461,7 +461,7 @@ | ... | @@ -461,7 +461,7 @@ |
461 | "file-entry-cache": "^6.0.1", | 461 | "file-entry-cache": "^6.0.1", |
462 | "functional-red-black-tree": "^1.0.1", | 462 | "functional-red-black-tree": "^1.0.1", |
463 | "glob-parent": "^6.0.1", | 463 | "glob-parent": "^6.0.1", |
464 | - "globals": "^13.6.0", | 464 | + "globals": "^13.15.0", |
465 | "ignore": "^5.2.0", | 465 | "ignore": "^5.2.0", |
466 | "import-fresh": "^3.0.0", | 466 | "import-fresh": "^3.0.0", |
467 | "imurmurhash": "^0.1.4", | 467 | "imurmurhash": "^0.1.4", |
... | @@ -1623,14 +1623,14 @@ | ... | @@ -1623,14 +1623,14 @@ |
1623 | }, | 1623 | }, |
1624 | "dependencies": { | 1624 | "dependencies": { |
1625 | "@eslint/eslintrc": { | 1625 | "@eslint/eslintrc": { |
1626 | - "version": "1.2.3", | 1626 | + "version": "1.3.0", |
1627 | - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.3.tgz", | 1627 | + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", |
1628 | - "integrity": "sha512-uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA==", | 1628 | + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", |
1629 | "requires": { | 1629 | "requires": { |
1630 | "ajv": "^6.12.4", | 1630 | "ajv": "^6.12.4", |
1631 | "debug": "^4.3.2", | 1631 | "debug": "^4.3.2", |
1632 | "espree": "^9.3.2", | 1632 | "espree": "^9.3.2", |
1633 | - "globals": "^13.9.0", | 1633 | + "globals": "^13.15.0", |
1634 | "ignore": "^5.2.0", | 1634 | "ignore": "^5.2.0", |
1635 | "import-fresh": "^3.2.1", | 1635 | "import-fresh": "^3.2.1", |
1636 | "js-yaml": "^4.1.0", | 1636 | "js-yaml": "^4.1.0", |
... | @@ -1943,11 +1943,11 @@ | ... | @@ -1943,11 +1943,11 @@ |
1943 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" | 1943 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" |
1944 | }, | 1944 | }, |
1945 | "eslint": { | 1945 | "eslint": { |
1946 | - "version": "8.15.0", | 1946 | + "version": "8.16.0", |
1947 | - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.15.0.tgz", | 1947 | + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.16.0.tgz", |
1948 | - "integrity": "sha512-GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6SA==", | 1948 | + "integrity": "sha512-MBndsoXY/PeVTDJeWsYj7kLZ5hQpJOfMYLsF6LicLHQWbRDG19lK5jOix4DPl8yY4SUFcE3txy86OzFLWT+yoA==", |
1949 | "requires": { | 1949 | "requires": { |
1950 | - "@eslint/eslintrc": "^1.2.3", | 1950 | + "@eslint/eslintrc": "^1.3.0", |
1951 | "@humanwhocodes/config-array": "^0.9.2", | 1951 | "@humanwhocodes/config-array": "^0.9.2", |
1952 | "ajv": "^6.10.0", | 1952 | "ajv": "^6.10.0", |
1953 | "chalk": "^4.0.0", | 1953 | "chalk": "^4.0.0", |
... | @@ -1965,7 +1965,7 @@ | ... | @@ -1965,7 +1965,7 @@ |
1965 | "file-entry-cache": "^6.0.1", | 1965 | "file-entry-cache": "^6.0.1", |
1966 | "functional-red-black-tree": "^1.0.1", | 1966 | "functional-red-black-tree": "^1.0.1", |
1967 | "glob-parent": "^6.0.1", | 1967 | "glob-parent": "^6.0.1", |
1968 | - "globals": "^13.6.0", | 1968 | + "globals": "^13.15.0", |
1969 | "ignore": "^5.2.0", | 1969 | "ignore": "^5.2.0", |
1970 | "import-fresh": "^3.0.0", | 1970 | "import-fresh": "^3.0.0", |
1971 | "imurmurhash": "^0.1.4", | 1971 | "imurmurhash": "^0.1.4", | ... | ... |
... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
14 | "license": "", | 14 | "license": "", |
15 | "dependencies": { | 15 | "dependencies": { |
16 | "@types/selenium-webdriver": "^4.1.0", | 16 | "@types/selenium-webdriver": "^4.1.0", |
17 | - "eslint": "^8.15.0", | 17 | + "eslint": "^8.16.0", |
18 | "mocha": "^10.0.0", | 18 | "mocha": "^10.0.0", |
19 | "selenium-webdriver": "^4.1.2" | 19 | "selenium-webdriver": "^4.1.2" |
20 | }, | 20 | }, | ... | ... |
1 | +//@ts-check | ||
2 | +//https://github.com/gatoona/AWS-Selenium | ||
3 | +import * as canvas from '../khcanvas.js' | ||
4 | +import * as rd from 'readline' | ||
5 | +import { assert } from 'console'; | ||
6 | + | ||
7 | +describe('khcanvas', () => { | ||
8 | + it('opening selenium', () => { | ||
9 | + //this.timeout(1000); | ||
10 | + canvas.using_selenium(async (driver) => { | ||
11 | + await driver.get("http://khuhub.khu.ac.kr"); | ||
12 | + await driver.getTitle().then(function (title) { | ||
13 | + console.log(title); | ||
14 | + }); | ||
15 | + }); | ||
16 | + }) | ||
17 | +}); | ||
18 | + | ||
19 | + | ||
20 | +describe('khcanvas', () => { | ||
21 | + it('get schedule', async () => { | ||
22 | + const rl = rd.createInterface({ | ||
23 | + input: process.stdin, | ||
24 | + output: process.stdout | ||
25 | + }) | ||
26 | + | ||
27 | + rl.question('a', async (a) => { | ||
28 | + rl.question('b', async (b) => { | ||
29 | + await canvas.get_schedule(a, b, new Date()) | ||
30 | + .then(it => { | ||
31 | + console.log(it) | ||
32 | + }) | ||
33 | + .catch(it => { | ||
34 | + console.log(it) | ||
35 | + throw new Error(); | ||
36 | + }) | ||
37 | + }) | ||
38 | + }) | ||
39 | + }) | ||
40 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment