2020. 7. 24. 21:33ㆍPython
The self COVID 19 diagnosis site of South Korea and
make it it do some processing automatically by python.
In South Korea, Each office of education(korean=교육청) by region supplies 'Self Diagnosis' site for COVID-19. Although many students have been bothered by it, they have to do it every 8 a.m even more not to go school.
so, I thought that something do covid-19 self diagnosis itself. Anyway I made it simply by python.
Let me introduce.
To make auto diagnosising program, I first visited office of education web site. and analyzed responses and requests. (I used Firefox Developer Edition for it)
Finally, I found some features.
-
1. All of requests's method is POST
-
2. It just only different domain name of offices and all the *.do files are same.
-
3. All of results are in resultSVO, JSON object. and all of datas must be received by JSON.(except HTML)
Before request code, I list request & response sequence.
-
Get the number of school from stv_cvd_co00_004.do
-
Send student datas to get qstnCrtfcNoEncpt from stv_cvd_co00_012.do
-
Send again to stv_cvd_co00_000.do to get survey html
-
Send survey data to stv_cvd_co01_000.do to refresh qstnCrtfcNoEncpt
-
Get result message by sending same data from stv_cvd_co02_000.do
Actually It's all of the code. we don't need any special Headers or some cookies..
So I list only requests body by sequence number.
1. {"schulNm":"school name"}
-> response : 'schulCode'(the number of school)
2. {"qstnCrtfcNoEncpt":"","rtnRsltCode":"","schulCode":schulCode,"schulNm":"school name","pName":"my name","frnoRidno":"birthday like 900503 (03, 05, 1990)","aditCrtfcNo":""}
-> response : 'qstnCrtfcNoEncpt'
3. {"qstnCrtfcNoEncpt":"qstnCrtfcNoEncpt","rtnRsltCode":"","schulCode":schulCode, "schulNm":"school name","pName":"my name","frnoRidno":"birthday like 900503 (03, 05, 1990)","aditCrtfcNo":""}
-> response -> survey html
4. { "rtnRsltCode":resultSVO.rtnRsltCode, "qstnCrtfcNoEncpt":resultSVO.qstnCrtfcNoEncpt, "schulNm":resultSVO.schulNm, "stdntName":resultSVO.stdntName , "rspns01":"1","rspns02":"1","rspns07":"0","rspns08":"0","rspns09":"0" }
rspns01... 02 07 are the questions that I answered.
5. { "rtnRsltCode":resultSVO.rtnRsltCode, "qstnCrtfcNoEncpt":resultSVO.qstnCrtfcNoEncpt, "schulNm":resultSVO.schulNm, "stdntName":resultSVO.stdntName , "rspns01":"1","rspns02":"1","rspns07":"0","rspns08":"0","rspns09":"0" }
send same data with 4.
you can get result message from the innerText of first 'p' tag in #content_detail1.
Last, my code.
import requests, json, pprint
from bs4 import BeautifulSoup
import urllib.parse
print("**e 형식, 남도는 *ne, 북도는 *be, 경기는 goe 등.")
state = input("지역코드 입력해주세요 (ex:경남 gne, 충북 cbe) : ")
host = 'eduro.gbe.kr' #교육청, 학교 api는 따로 신청해야함;;
domain = 'https://'+host
req = requests.session()
res = req.get(domain+"/hcheck/index.jsp")
school = input("school : ")
name = input("name : ")
birthday = input("birthday (060405, 06 4, 5) : ")
body = {"schulNm":school}
header = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/| 20100101 Firefox/79.0",
"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
}
json = req.post(domain+"/stv_cvd_co00_004.do", data=body, headers=header).json()
if(json["resultSVO"]["rtnRsltCode"] == "SUCCESS"):
print("success to get school data")
schulCode = json["resultSVO"]["schulCode"]
body = {"qstnCrtfcNoEncpt":"","rtnRsltCode":"","schulCode":schulCode,"schulNm":school,"pName":name,"frnoRidno":birthday,"aditCrtfcNo":""}
json = req.post(domain+"/stv_cvd_co00_012.do", data=body, headers=header).json()
rsltCode = json["resultSVO"]["rtnRsltCode"]
body["rtnRsltCode"] = rsltCode
print("========================================")
if(rsltCode == "SUCCESS"):
print("personal data success")
qstnCrtfcNoEncpt = json["resultSVO"]["qstnCrtfcNoEncpt"]
body["qstnCrtfcNoEncpt"] = qstnCrtfcNoEncpt
html = req.post(domain+"/stv_cvd_co00_000.do", data=body, headers=header).text
soup = BeautifulSoup(html, 'html.parser')
form = soup.find("form", {"id":"infoForm"})
bestAnswers = {}
titles = []
for t in form.find_all("table"):
titles.append(t.find("th", {"scope":"row"}).text)
input = t.find("label").find("input")
bestAnswers[input["name"]] = input["value"]
body.update(bestAnswers)
json = req.post(domain+"/stv_cvd_co01_000.do", data=body, headers=header).json()
if(json["resultSVO"]["rtnRsltCode"] == "SUCCESS"):
print("o.k. to submit survey")
html = req.post(domain+"/stv_cvd_co02_000.do", data=body, headers=header).text
soup = BeautifulSoup(html, 'html.parser')
resultMsg = soup.find("div", {"id":"content_detail1"}).find("p").text
print("result message")
print(resultMsg.strip())
print("It've done")
print("========================================")
else:
print("2. failed to cert personal data")
else:
print("1.failed to get school data")
pprint.pprint(body)
'Python' 카테고리의 다른 글
손실함수에 대해서 (0) | 2022.07.24 |
---|---|
[Kaggle] Drug Classification 데이터셋을 이용한 KNN 분류 실습 (0) | 2022.01.16 |
[파이썬][딥러닝] 3층 순방향 신경망 구현하기 (0) | 2020.03.31 |
[파이썬][딥러닝] 퍼셉트론 - 활성화 함수 (0) | 2020.03.28 |
[파이썬][딥러닝] Perceptron 퍼셉트론 (0) | 2020.03.28 |