남들이 안해본것을 해서 궁극적인 지식의 완성을 목표로 하는 블로그입니다. 제품리뷰 , IT, 프로그래밍 관련글을 포스팅합니다.
from bs4 import BeautifulSoup import requests import operator import re import os print('------ 리로스쿨 내신 평균 산출기 ------') print('예체능은 집계에서 제외됩니다') print('1학년 20% (학기당 10%), 2학년 30%(학기당 15%)') print('3학년 1학기 50% 로 계산합니다.') print('제작 - File(pgh268400@naver.com)') print('-------------------------------------') #ID, PW 입력 #id = os.getenv("USER_ID") #pw = os.getenv("USER_PASSWORD") id = "" pw = "" # 사이트 접속 url = "https://주소.riroschool.kr/home.php" headers = { 'Content-Type': 'application/json; charset=utf-8', 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', 'Host' : '주소.riroschool.kr', 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Accept-Language' : 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7', 'Cache-Control':'max-age=0', 'Connection' : 'Keep-Alive' } res = requests.session() #세션 유지 response = res.get(url, headers=headers) #로그인 하기 bs = BeautifulSoup(response.text, 'html.parser') URI = bs.find('input', {'name': 'URI'}).get('value') #URI 값 가져오기 print('URI :', URI) headers = { 'Host': '주소.riroschool.kr', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Origin': 'https://주소.riroschool.kr', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36', 'Sec-Fetch-User': '?1', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Mode': 'navigate', 'Referer': 'https://주소.riroschool.kr/home.php', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7' } url = "https://주소.riroschool.kr/user.php" _data = "URI=" + URI + "&action=user_login&club=index&mid=" + id + "&mpass=" + pw cookies = {'alarm': '0', 'oldversion' : '0'} response = res.post(url, headers=headers, data = _data, cookies = cookies) print(response.text) # 내신 성적 조회 이동 url = "https://주소.riroschool.kr/board.php?" _data = "action=list&db=1010&uid=&hide_plan=&code=&my_id=" + id + "&pw=" + pw response = res.post(url, headers=headers, data = _data, cookies = cookies) #print(response.text) #파싱 시작 bs = BeautifulSoup(response.text, 'html.parser') dict = {} for option in bs.find_all('option'): if '종합' in option.text: #종합만 가져오기 print ('{}, uid : {}'.format(option.text, option['value'])) dict[option.text] = option['value'] rank = {} title, grade = "", "" all_list = [] for key,value in dict.items(): url = "https://주소.riroschool.kr/board.php?action=list&db=1010&uid=" + value print('-------------' + key + '-------------') response = res.get(url, headers=headers, cookies = cookies) bs = BeautifulSoup(response.text, 'html.parser') idx = 0 for option in bs.find_all('td'): idx+= 1 if idx > 40: if str(idx)[-1] == '1' or str(idx)[-1] == '6': #1번째나 6번째로 오는수에 과목명이온다 print('제목 : ', option.text) all_list.append(option.text) #리스트 추가 m = re.search('[0-9]', option.text) print('수업시수 :', m.group()) title = option.text all_list.append(m.group()) #수업시수 추가 if idx % 5 == 0: #5의 배수배로 등급이 나온다 if option.text == '': print('등급 : *') else: print('등급 : ', option.text) grade = option.text all_list.append(option.text) # 등급추가 l = [title,grade] rank[title] = grade print('-------------------------------------') print(all_list) # 리스트 출력 #print('--------------Dictionary--------------') #for key, value in rank.items(): # print(key, value)
ID, PW 란에 자기 아이디 비밀번호 넣으면 자동으로 나옵니다.
원래는 그냥 저장용으로 비밀번호 걸어놨었는데 필요하신 분들이 있을까 해서 공유합니다 ^^
[Python] 리로스쿨 로그인 + 내신 가져오기
ID, PW 란에 자기 아이디 비밀번호 넣으면 자동으로 나옵니다.
원래는 그냥 저장용으로 비밀번호 걸어놨었는데 필요하신 분들이 있을까 해서 공유합니다 ^^
'프로그래밍 > Python' 카테고리의 다른 글
COMMENT WRITE