JoeanAmier 01111cc401 fix: 修复项目功能异常
1. 修复 ScannerError 错误
2. 优化作品数据提取逻辑
3. 移除 Cookie 参数

Closes #124
Closes #126
2024-07-28 22:21:03 +08:00

41 lines
1.1 KiB
Python

from httpx import HTTPError
from source.module import ERROR
from source.module import Manager
from source.module import logging
from source.module import retry
__all__ = ["Html"]
class Html:
def __init__(self, manager: Manager, ):
self.retry = manager.retry
self.message = manager.message
self.client = manager.request_client
@retry
async def request_url(
self,
url: str,
content=True,
log=None,
**kwargs,
) -> str:
try:
response = await self.client.get(
url,
**kwargs,
)
response.raise_for_status()
return response.text if content else str(response.url)
except HTTPError as error:
logging(log, str(error), ERROR)
logging(
log, self.message("网络异常,请求 {0} 失败").format(url), ERROR)
return ""
@staticmethod
def format_url(url: str) -> str:
return bytes(url, "utf-8").decode("unicode_escape")