-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_eclass.py
More file actions
65 lines (55 loc) · 2.04 KB
/
check_eclass.py
File metadata and controls
65 lines (55 loc) · 2.04 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python3
import codecs
import http.cookiejar
import os
import ssl
import time
import re
import urllib
from bs4 import BeautifulSoup
MAIN_URL = 'http://eclass.dongguk.edu/'
PARSER = 'lxml'
if os.name == 'nt':
PARSER = 'html.parser'
# LOGIN INFO
LOGIN_URL = 'https://eclass.dongguk.edu/User.do?cmd=loginUser'
LOGIN_INFO = {
'userDTO.userId': 'YourID',
'userDTO.password': 'YourPW'
}
# LOGIN OPERATION
cookie_jar = http.cookiejar.LWPCookieJar()
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_handler = urllib.request.HTTPSHandler(context=ssl_context)
cj_processor = urllib.request.HTTPCookieProcessor(cookie_jar)
opener = urllib.request.build_opener(ssl_handler, cj_processor)
urllib.request.install_opener(opener)
login_request = urllib.parse.urlencode(LOGIN_INFO)
req = urllib.request.Request(LOGIN_URL, login_request.encode('UTF-8'))
res = urllib.request.urlopen(req)
# GET STUDY MAIN PAGE
url1 = 'http://eclass.dongguk.edu/Study.do?cmd=viewMyCourse&curriculumType=degree&studyAuthor=class_learner'
res = opener.open(url1)
data = res.read().decode('utf-8')
soup = BeautifulSoup(data, PARSER)
html_semesterform = soup.find('span', {'class': 'selectForm'})
html_semesterlist = html_semesterform.find('span', {'class': 'list'})
html_semesteritems = html_semesterlist.find_all('a')
semester_list = []
semester_href = []
semester_name_regex = re.compile(r'[\s\S]*([0-9]{4}년도 .*학기)[\s\S]*')
for item in html_semesteritems:
semester_list.append(semester_name_regex.sub(r'\1', item.text))
semester_href.append(item['href'])
for name, href in zip(semester_list, semester_href):
print('\n' + name + '에 수강했던 강의 목록\n')
res = opener.open(MAIN_URL + href)
data = res.read().decode('utf-8')
soup = BeautifulSoup(data, PARSER)
course_list = soup.find_all('div', {'class', 'mystudy_directory first'})
for course in course_list:
t = course.find('h4').find('span').text
b = re.sub(r'\n', r'', t)
c = re.sub(r'\s*(\S.*)', r'\1', b)
print(c)
print('\n' + '-' * 20)