Skip to content

Commit

Permalink
[Add] 정기 커밋
Browse files Browse the repository at this point in the history
  • Loading branch information
rover0811 committed Dec 1, 2022
1 parent 42f15c5 commit aa877e0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@ tableitems.html
./result
./source
result.xlsx
web/style.css
web/index.html
result/why.html
result/variables.txt
result/seleniumpath.txt
result/response.html
result/practice.xlsx
result/a.html
python/__pycache__/selenium.cpython-39.pyc
MyeongJin/__pycache__/parse.cpython-39.pyc
MyeongJin/__pycache__/constant.cpython-39.pyc
chromedriver.exe
API/__pycache__/main.cpython-39.pyc
15 changes: 15 additions & 0 deletions API/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
31 changes: 31 additions & 0 deletions MyeongJin/constant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
LOGIN_URL = "https://smartid.ssu.ac.kr/Symtra_sso/smln_pcs.asp"
PORTAL_URL = "https://saint.ssu.ac.kr/irj/portal"
GRADE_URL = 'https://ecc.ssu.ac.kr/sap/bc/webdynpro/sap/ZCMB3W0017'
SAPTOKEN_URL = "https://saint.ssu.ac.kr/webSSO/sso.jsp?sToken="


SESSION_HEADERS = {
'Accept': '*/*',
'Accept-Encoding': "gzip, deflate, br",
"Accept-Language": "ko-KR",
'Connection': 'keep-alive',
'Host': "ecc.ssu.ac.kr",
'Sec-Fetch-Dest': 'documnet',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'none',
'X-XHR-Logon': 'accept',
'Upgrade-Insecure-Requests': '1',
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
}

# NEW_SESSION_HEADERS = {
# 'Accept': '*/*',
# "Accept-Language": "ko-KR",
# # 'Connection': 'keep-alive',
# # 'Host': "ecc.ssu.ac.kr",
# 'Sec-Fetch-Dest': 'empty',
# 'Sec-Fetch-Mode': 'cors',
# 'Sec-Fetch-Site': 'same-origin',
# 'X-XHR-Logon': 'accept',
# "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
# }
12 changes: 12 additions & 0 deletions MyeongJin/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re
from bs4 import BeautifulSoup

def parse_grade(page_source):
soup = BeautifulSoup(page_source, 'html.parser')
grade_table = soup.find('tbody', {'id': re.compile('WD0...-contentTBody')})
column_names = ['이수학년도','이수학기','과목코드','과목명','과목학점','성적','등급','교수명','비고']
check_text = lambda tag: tag.select_one('span').text if tag else None
row_datas = [[check_text(td) for td in tr.select('td > span')] for tr in grade_table.select('tr')[1:]]
grade_data = [{col_name:row_data for col_name, row_data in zip(column_names, row)} for row in row_datas]
print(grade_data)
return grade_data
42 changes: 42 additions & 0 deletions python/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import requests
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
# ser = Service("C:/Users/rover0811/chromedriver.exe") # 크롬 드라이버 잡아주는 것
# op = webdriver.ChromeOptions() # initial
# op.add_experimental_option("excludeSwitches", ["enable-logging"]) # option 주기
# op.add_argument('--window-size=1920,1080')
# s = webdriver.Chrome(service=ser, options=op) # 초기화


#유세인트 초기 로그인 api
login_url = "https://smartid.ssu.ac.kr/Symtra_sso/smln_pcs.asp"
user_agent = ""

user_data = {
"in_tp_bit": "0",
"rqst_caus_cd": "03",
"userid": "",
"pwd": ""
}

header = {
"referer": login_url,
"user-agent": user_agent
}

session = requests.Session()

with session as s:
s.post(login_url, headers=header, data=user_data)
login_cookies = requests.utils.dict_from_cookiejar(s.cookies)
session_token = login_cookies['sToken']

#여기에 전달 받은 토큰을 넘겨주면 세션이 생성됨
pass_token_url = f"https://saint.ssu.ac.kr/webSSO/sso.jsp?sToken={session_token}"

s.get(pass_token_url, headers=header)
header["referer"] = pass_token_url

#세션을 통해 유세인트 접근하면 접속 성공
res = s.get("https://saint.ssu.ac.kr/irj/portal", headers=header)
print(res.text)

0 comments on commit aa877e0

Please sign in to comment.