본문으로 바로가기

파일의 IT 블로그

  1. Home
  2. 프로그래밍/Python
  3. [Python] 리로스쿨 로그인 + 내신 가져오기

[Python] 리로스쿨 로그인 + 내신 가져오기

· 댓글개 · KRFile
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 란에 자기 아이디 비밀번호 넣으면 자동으로 나옵니다.

원래는 그냥 저장용으로 비밀번호 걸어놨었는데 필요하신 분들이 있을까 해서 공유합니다 ^^

 

SNS 공유하기
💬 댓글 개
이모티콘창 닫기
울음
안녕
감사해요
당황
피폐

이모티콘을 클릭하면 댓글창에 입력됩니다.