Skip to content

Instantly share code, notes, and snippets.

@kiwiyou
Created September 22, 2020 15:03
Show Gist options
  • Save kiwiyou/6476cc73a05937bd0a5dd6a33aabe395 to your computer and use it in GitHub Desktop.
Save kiwiyou/6476cc73a05937bd0a5dd6a33aabe395 to your computer and use it in GitHub Desktop.
교육청 학급홈페이지 로그인 시스템
import requests
import re
class SchoolPage:
def __init__(self, site_id: str, return_url: str, fail_url: str, session=requests.Session()):
# 로그인 페이지 참조
self.site_id = site_id
self.return_url = return_url
self.fail_url = fail_url
self.reset()
def login(self, id: str, pw: str):
login_data = {
'siteId': self.site_id,
'returnUrl': self.return_url,
'failUrl': self.fail_url,
'act': 'userLogin',
'user_id': id,
'password': pw,
}
res = self.session.post('http://member.newhosting.ssem.or.kr/sso/sso/saml/CreateRequestServlet', data=login_data)
path = re.search("document.location = '(.+?)'", res.text).group(1)
res = self.session.get('http://member.newhosting.ssem.or.kr' + path)
request_data = {
'domainName': re.search('<input name="domainName" type="hidden" value="(.+?)">', res.text).group(1),
'SAMLResponse': re.search('<textarea rows=10 cols=80 name="SAMLResponse">(.+?)</textarea>', res.text, re.DOTALL).group(1),
'RelayState': re.search('<textarea rows=10 cols=80 name="RelayState">(.+?)</textarea>', res.text).group(1),
}
res = self.session.post(re.search('<form name="acsForm" action="(.+?)" method="post">', res.text).group(1), data=request_data)
acs_data = {
'mid': re.search('<input type=hidden name=mid value="(.+?)">', res.text).group(1),
'sessionno': re.search('<input type=hidden name=sessionno value="(.+?)">', res.text).group(1),
'signature': re.search('<input type=hidden name=signature value="(.+?)">', res.text).group(1),
}
self.session.post(re.search('<form name=loginform method=post action="(.+?)">', res.text).group(1), data=acs_data)
def reset(self):
self.session = requests.Session()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment