refactor: 删除登录表单里没有引用的字段和正则

This commit is contained in:
2026-10-25 07:09:54 +08:00
parent 6b84a5e406
commit 6558e5576a
+1 -12
View File
@@ -10,7 +10,7 @@ import re
from collections import deque
from collections.abc import AsyncIterator
from dataclasses import dataclass, field
from urllib.parse import quote, urlencode, urljoin
from urllib.parse import quote, urlencode
import httpx
from cryptography.hazmat.primitives import serialization
@@ -36,9 +36,6 @@ from app.platform.sign import build_sign, wfs_sig
_EXECUTION = re.compile(r'name="execution"\s+value="([^"]+)"', re.I)
_PUBLIC_KEY = re.compile(r'setPublicKey\("([^"]+)"\)')
_FORM_ACTION = re.compile(r'<form[^>]*id="fm1"[^>]*action="([^"]*)"', re.I)
_FORM_ACTION_REV = re.compile(r'<form[^>]*action="([^"]*)"[^>]*id="fm1"', re.I)
_ERROR_TEXT = re.compile(r'id="errMsg"[^>]*>(.*?)</', re.S)
class NqiError(Exception):
@@ -110,7 +107,6 @@ def _transport_error(exc: Exception) -> None:
class LoginChallenge:
execution: str
public_key: str
form_action: str
captcha_png: bytes
page_url: str
captcha_type: str = "image/jpeg"
@@ -190,12 +186,6 @@ class NqiClient:
if not execution or not public_key:
raise NqiError("登录页没有返回加密参数,请稍后重试")
page_url = login_page_url(str(response.url))
action_match = _FORM_ACTION.search(html) or _FORM_ACTION_REV.search(html)
action = action_match.group(1) if action_match and action_match.group(1) else page_url
if action.startswith("/"):
action = ORIGIN + action
elif not action.startswith("http"):
action = urljoin(page_url, action)
try:
captcha = await self.client.get(CAS_CAPTCHA, headers={"Referer": page_url})
except (httpx.TimeoutException, httpx.RequestError) as exc:
@@ -205,7 +195,6 @@ class NqiClient:
return LoginChallenge(
execution=execution.group(1),
public_key=public_key.group(1),
form_action=action,
captcha_png=captcha.content,
page_url=page_url,
captcha_type=_media_type(captcha),