规范化 URL,登录页返回 404 时自动尝试 /jwglxt/。
改用当前有效的 DgXscj 成绩接口。 同步更新配置说明。
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
> 程序会自动填充 `URL` 尾部的 `xtgl/login_slogin.html`,因此你无需重复添加
|
> 程序会自动填充 `URL` 尾部的 `xtgl/login_slogin.html`,因此你无需重复添加
|
||||||
|
|
||||||
> 对于部分教务系统,可能需要在 `URL` 中添加 `jwglxt` 路径,如:`https://www.klaio.top/jwglxt/`
|
> 对于部署在 `jwglxt` 路径下的教务系统,程序会在根路径登录页不存在时自动尝试该路径;也可以直接填写完整地址,如:`https://www.klaio.top/jwglxt/`
|
||||||
|
|
||||||
| Name | 例子 | 说明 |
|
| Name | 例子 | 说明 |
|
||||||
| -------- | ---------------------- | ------------------------------------------------------------------------- |
|
| -------- | ---------------------- | ------------------------------------------------------------------------- |
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ def get_grade(student_client, output_type="none"):
|
|||||||
while attempts > 0:
|
while attempts > 0:
|
||||||
|
|
||||||
# 调用student_client的get_grade方法获取成绩信息
|
# 调用student_client的get_grade方法获取成绩信息
|
||||||
grade_data = student_client.get_grade().get("data", {})
|
# 学生成绩查询目前使用 cjcx_cxDgXscj 接口
|
||||||
|
grade_data = student_client.get_grade(use_personal_info=True).get("data", {})
|
||||||
grade = grade_data.get("courses", [])
|
grade = grade_data.get("courses", [])
|
||||||
|
|
||||||
# 如果grade不为空,跳出循环
|
# 如果grade不为空,跳出循环
|
||||||
|
|||||||
+14
-6
@@ -5,7 +5,7 @@ import re
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin, urlparse
|
||||||
import requests
|
import requests
|
||||||
import rsa
|
import rsa
|
||||||
from pyquery import PyQuery as pq
|
from pyquery import PyQuery as pq
|
||||||
@@ -34,7 +34,6 @@ class Client:
|
|||||||
|
|
||||||
def __init__(self, cookies={}, **kwargs):
|
def __init__(self, cookies={}, **kwargs):
|
||||||
# 基础配置
|
# 基础配置
|
||||||
self.base_url = kwargs.get("base_url")
|
|
||||||
self.raspisanie = kwargs.get("raspisanie", RASPIANIE)
|
self.raspisanie = kwargs.get("raspisanie", RASPIANIE)
|
||||||
self.ignore_type = kwargs.get("ignore_type", [])
|
self.ignore_type = kwargs.get("ignore_type", [])
|
||||||
self.detail_category_type = kwargs.get("detail_category_type", [])
|
self.detail_category_type = kwargs.get("detail_category_type", [])
|
||||||
@@ -42,23 +41,32 @@ class Client:
|
|||||||
Client.raspisanie = self.raspisanie
|
Client.raspisanie = self.raspisanie
|
||||||
Client.ignore_type = self.ignore_type
|
Client.ignore_type = self.ignore_type
|
||||||
|
|
||||||
self.key_url = urljoin(self.base_url, "xtgl/login_getPublicKey.html")
|
|
||||||
self.login_url = urljoin(self.base_url, "xtgl/login_slogin.html")
|
|
||||||
self.kaptcha_url = urljoin(self.base_url, "kaptcha")
|
|
||||||
self.headers = requests.utils.default_headers()
|
self.headers = requests.utils.default_headers()
|
||||||
self.headers["Referer"] = self.login_url
|
|
||||||
self.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
|
self.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
|
||||||
self.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
|
self.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
|
||||||
|
self._set_base_url(kwargs.get("base_url"))
|
||||||
self.sess = requests.Session()
|
self.sess = requests.Session()
|
||||||
self.sess.keep_alive = False
|
self.sess.keep_alive = False
|
||||||
self.cookies = cookies
|
self.cookies = cookies
|
||||||
|
|
||||||
|
def _set_base_url(self, base_url):
|
||||||
|
"""规范化教务系统根地址并同步登录相关接口。"""
|
||||||
|
self.base_url = base_url.rstrip("/") + "/"
|
||||||
|
self.key_url = urljoin(self.base_url, "xtgl/login_getPublicKey.html")
|
||||||
|
self.login_url = urljoin(self.base_url, "xtgl/login_slogin.html")
|
||||||
|
self.kaptcha_url = urljoin(self.base_url, "kaptcha")
|
||||||
|
self.headers["Referer"] = self.login_url
|
||||||
|
|
||||||
def login(self, sid, password):
|
def login(self, sid, password):
|
||||||
"""登录教务系统"""
|
"""登录教务系统"""
|
||||||
need_verify = False
|
need_verify = False
|
||||||
try:
|
try:
|
||||||
# 登录页
|
# 登录页
|
||||||
req_csrf = self.sess.get(self.login_url, headers=self.headers, timeout=self.timeout)
|
req_csrf = self.sess.get(self.login_url, headers=self.headers, timeout=self.timeout)
|
||||||
|
# 部分学校将正方系统部署在 /jwglxt/ 下;根路径登录页不存在时自动兼容
|
||||||
|
if req_csrf.status_code == 404 and urlparse(self.base_url).path in ("", "/"):
|
||||||
|
self._set_base_url(urljoin(self.base_url, "jwglxt/"))
|
||||||
|
req_csrf = self.sess.get(self.login_url, headers=self.headers, timeout=self.timeout)
|
||||||
if req_csrf.status_code != 200:
|
if req_csrf.status_code != 200:
|
||||||
return {"code": 2333, "msg": "教务系统挂了"}
|
return {"code": 2333, "msg": "教务系统挂了"}
|
||||||
# 获取csrf_token
|
# 获取csrf_token
|
||||||
|
|||||||
Reference in New Issue
Block a user