Last active
August 17, 2019 04:18
-
-
Save ShapeLayer/0f7bb41c0099972a2da41ed5a5de334e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
당신의 수강신청, 자동화로 대체되었다 | |
==== | |
## 의존성 모듈 설치 | |
``` | |
pip install requests | |
pip install beautifulsoup4 | |
``` | |
## 변수 셋 | |
``` | |
login_stu_grade : 학년 | |
login_stu_course : 학과 | |
login_stu_class : 반 | |
login_stu_bunho : 번호 | |
login_stu_name : 이름 | |
login_stu_passwd : 비밀번호 | |
target_set : 강의 고유 구분자 | |
log_set : 마지막 요청 파일 html | |
sec : 재시도 | |
``` | |
''' | |
import requests | |
from time import sleep | |
from bs4 import BeautifulSoup as bs | |
import threading | |
s = requests.Session() | |
url = { | |
'login' : 'https://www.dbdbschool.kr/member/login/sn/748', | |
'list' : 'https://www.dbdbschool.kr/af/st_lec/lists/sn/748', | |
'submit' : 'https://www.dbdbschool.kr/af/st_lec/sin/p/1/sn/748' | |
} | |
data = { | |
'login_stu_grade' : '2', | |
'login_stu_course' : '3', | |
'login_stu_class' : '8', | |
'login_stu_bunho' : '24', | |
'login_stu_name' : '박종현', | |
'login_stu_passwd' : '' | |
} | |
sec = 0 | |
headers = { | |
'User-Agent' : 'Mozilla/5.0' | |
} | |
log_set = True | |
target_set = ['308759', '308760'] | |
def tag_find(obj, tar): | |
return obj.find('input', {'name': tar})['value'] | |
def soup_set(content): | |
return bs(content, 'html.parser') | |
def sin(target): | |
print('요청 | 리스트 데이터 가져옴') | |
page = s.get(url['list']).text | |
soup = soup_set(page) | |
soup = soup.find('form', {'name': 'fm_lec_sin'}) | |
csrf = soup.find('input', {'name': 'csrf_test_name'})['value'] | |
print('결과 | 신청 csrf: {}'.format(csrf)) | |
data = { | |
'num' : target, | |
'csrf_test_name' : csrf | |
} | |
commit = s.post(url['submit'], data=data, headers=headers) | |
print('응답 | {}'.format(commit.status_code)) | |
if log_set: | |
with open('log.html', 'w', encoding='utf-8') as f: | |
f.write(commit.text) | |
print('요청 | 로그인 데이터 가져옴') | |
page = s.get(url['login']).text | |
soup = soup_set(page) | |
data['csrf_test_name'] = tag_find(soup, 'csrf_test_name') | |
data['login_user_grp'] = tag_find(soup, 'login_user_grp') | |
data['res_ser_date'] = tag_find(soup, 'res_ser_date') | |
data['ready_cli_date'] = tag_find(soup, 'ready_cli_date') | |
data['ready_cli_gmt'] = tag_find(soup, 'ready_cli_gmt') | |
print('결과 | 로그인 csrf: {}'.format(data['csrf_test_name'])) | |
page = s.post(url['login'], data=data, headers=headers) | |
print('응답 | {}'.format(page.status_code)) | |
count = 1 | |
t = [] | |
j = 0 | |
while True: | |
t += [[]] | |
for i in range(len(target_set)): | |
t[j] += [threading.Thread(target=sin, args=([target_set[i]]))] | |
t[j][i].daemon = False | |
t[j][i].start() | |
print('강의 {} 시도: {}회째'.format(target_set[i], j)) | |
sleep(sec) | |
j += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment