Python 으로 스마트 캠퍼스 매일 수업 표를 가 져 와 메 일 로 자동 으로 보 냅 니 다.
1.1 로그 인 인터페이스 관찰
나 는 우리 가 계 정과 비밀 번 호 를 입력 한 후에 이런 링크 가 나타 나 는 것 을 쉽게 발견 할 수 있다.Response 가 돌아 온 것 은 false 이다.
http://sso.cqcet.edu.cn/verificationCode?userCode={username}
이곳 의username
은 당신 의
을 말 합 니 다.false
로그 인 할 때 인증 코드 를 입력 할 필요 가 없다 는 것 을 나타 낸다.Response 가 되 돌아 오 는 것 이true
일 때 인증 코드 를 입력 해 야 합 니 다.1.2 로그 인 요청 과정 관찰
우 리 는 Request URL 이
http://sso.cqcet.edu.cn/uaa/login_process
라 는 것 을 발견 할 수 있 습 니 다.가지 고 있 는 폼 데 이 터 는 다음 과 같 습 니 다.
1.3 방문 시간표 의 url 요청 관찰
시간표 가 있 는 곳 을 찾 아 클릭 하면 Request URL 이
http://ossc.cqcet.edu.cn/api/schedule/query
인 것 을 발견 할 수 있 습 니 다.너 는 Preview 에서 시간표 정 보 를 발견 할 수 있다.그러나 이 링크 를 더 블 클릭 하면 다음 과 같은 오류 가 발생 합 니 다.
원인:이 링크 에 접근 하려 면 요청 부하 가 필요 합 니 다.
Date 는 조회 의 구체 적 인 어느 날 의 수업 표를 나타 낸다.
코드 구현
2.1 해당 의존 라 이브 러 리 설치
키보드 누 르 기
Win+R
다음 화면 으로 이동:입력
cmd
,다음 화면 에 입장:입력
pip install
하면 설치 할 수 있 습 니 다.2.2 의존 라 이브 러 리 가 져 오기
import json
import requests
import uuid # ,
import yagmail #
import random
import datetime #
from fake_useragent import UserAgent # UserAgent
2.3 일부 계 정 비밀번호 의 기록
username = '********' #
passwd = '*********' #
now_time = datetime.datetime.now ().strftime('%Y-%m-%d') #
contents = '' #
# uuid
uuid = uuid.uuid4()
# UA
def get_random_ua():
ua = UserAgent()
return ua.random
2.4 url 집계 및 기타 준비
# url
code_url = f'http://sso.cqcet.edu.cn/validata/code/{uuid}' # url
url = f'http://sso.cqcet.edu.cn/verificationCode?userCode={username}' # url
login_url = 'http://sso.cqcet.edu.cn/uaa/login_process' # url
info_url = 'http://ossc.cqcet.edu.cn/getUserInfo' # url
schedule_url = 'http://ossc.cqcet.edu.cn/api/schedule/query' # url
#
headers = {
'User-Agent': get_random_ua()
}
session = requests.session()
#
def getImgCode():
img_name = str(uuid) + '.jpg'
img_data = requests.get(url=code_url, headers=headers).content
with open(img_name, 'wb') as fp:
fp.write(img_data)
print(' , !')
2.5 구체 적 과정
#
def getImgCode():
img_name = str(uuid) + '.jpg'
img_data = requests.get(url=code_url, headers=headers).content
with open(img_name, 'wb') as fp:
fp.write(img_data)
print(' , !')
#
isCode = session.get(url=url, headers=headers).text
if isCode == 'true':
getImgCode()
# img_code
img_code = input(' :')
else:
img_code = ''
data = {
'type': '1',
'deviceId': str(uuid),
'username': username,
'password': passwd,
'img_code': img_code
}
response = session.post(url=login_url, data=data)
login_text = response.text
# print(response.status_code) # 200 !
#
info = session.get(url=info_url).text
info_data = json.loads(info) # json
# print(info_data)
# pprint.pprint(info_data)
contents += ' ' + info_data['user']['name'] + ' :
'
#
schedule_json = {
'endDate': now_time,
'limit': '10',
'page': '1',
'startDate': now_time,
'type': '0'
}
schedule = session.post(url=schedule_url, json=schedule_json).text
schedule_data = json.loads(schedule) # json
# pprint.pprint(len(schedule_data['data'])) #
#
if len(schedule_data['data']) == 0:
re_list = [' , ~', ' , !', ' , ~
?', ' , ~']
contents += ' ' + re_list[random.randint(0, 3)]
else:
contents += ' ~
<hr/><table border="1" cellpadding="2" ' \
'cellspacing="0"><tr><th> </th><th> </th><th> </th><th> </th></tr>'
for course_table in schedule_data['data']:
# print(course_table)
time = '<tr><td>' + course_table['date'] + ' ' + course_table['time'] + '</td>'
title = '<td>' + course_table['activity']['title'] + '</td>'
teacher = '<td>' + course_table['activity']['remarks'] + '</td>'
classroom = '<td>' + course_table['activity']['address'] + '</td></tr>'
contents += time + title + teacher + classroom
contents += '</table>'
2.6 얻 은 수업 시간표 정 보 를 우편 으로 자신 에 게 보낸다.
#
def to_mail(content):
yag = yagmail.SMTP(
user='sm*****[email protected]',
host='smtp.qq.com',
password="pdxj**********", # , 。 yagmail 。
smtp_ssl=True)
yag.send(to=['[email protected]','s*****[email protected]'],
subject=' , ~',
contents=contents)
to_mail(contents) #
3.효과 전시파 이 썬 으로 스마트 캠퍼스 일 일 수업 표를 받 아 자동 으로 메 일 로 보 내 는 글 을 소개 합 니 다.더 많은 파 이 썬 이 수업 표를 받 은 후 메 일 로 보 내 는 내용 은 예전 의 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 도 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.