mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
perf(request.py): 优化 headers 处理逻辑
1. 修复已登录 Cookie 无法获取具体数据的问题 2. 更新项目依赖库版本 Closes #206
This commit is contained in:
parent
86b5de6687
commit
ea63059dbf
@ -13,13 +13,13 @@ dependencies = [
|
||||
"aiosqlite>=0.21.0",
|
||||
"click>=8.1.8",
|
||||
"emoji>=2.14.1",
|
||||
"fastapi>=0.115.8",
|
||||
"fastapi>=0.115.9",
|
||||
"httpx[socks]>=0.28.1",
|
||||
"lxml>=5.3.1",
|
||||
"pyperclip>=1.9.0",
|
||||
"pyyaml>=6.0.2",
|
||||
"rookiepy>=0.5.6",
|
||||
"textual>=1.0.0",
|
||||
"textual>=2.1.2",
|
||||
"uvicorn>=0.34.0",
|
||||
]
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ click==8.1.8
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
emoji==2.14.1
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
fastapi==0.115.8
|
||||
fastapi==0.115.9
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
httpx[socks]==0.28.1
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
@ -20,7 +20,7 @@ pyyaml==6.0.2
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
rookiepy==0.5.6
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
textual==2.0.4
|
||||
textual==2.1.2
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
uvicorn==0.34.0
|
||||
# via xhs-downloader (pyproject.toml)
|
||||
|
||||
@ -18,7 +18,6 @@ class Html:
|
||||
self.retry = manager.retry
|
||||
self.client = manager.request_client
|
||||
self.headers = manager.headers
|
||||
self.blank_headers = manager.blank_headers
|
||||
|
||||
@retry
|
||||
async def request_url(
|
||||
@ -29,8 +28,7 @@ class Html:
|
||||
cookie: str = None,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
headers = self.select_headers(
|
||||
url,
|
||||
headers = self.update_cookie(
|
||||
cookie,
|
||||
)
|
||||
try:
|
||||
@ -52,6 +50,8 @@ class Html:
|
||||
)
|
||||
await sleep_time()
|
||||
return str(response.url)
|
||||
case _:
|
||||
raise ValueError
|
||||
except HTTPError as error:
|
||||
logging(
|
||||
log, _("网络异常,{0} 请求失败: {1}").format(url, repr(error)), ERROR
|
||||
@ -62,14 +62,11 @@ class Html:
|
||||
def format_url(url: str) -> str:
|
||||
return bytes(url, "utf-8").decode("unicode_escape")
|
||||
|
||||
def select_headers(
|
||||
def update_cookie(
|
||||
self,
|
||||
url: str,
|
||||
cookie: str = None,
|
||||
) -> dict:
|
||||
if "explore" not in url:
|
||||
return self.blank_headers
|
||||
return self.headers | {"Cookie": cookie} if cookie else self.headers
|
||||
return self.headers | {"Cookie": cookie} if cookie else self.headers.copy()
|
||||
|
||||
async def __request_url_head(
|
||||
self,
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
**项目更新内容:**
|
||||
|
||||
1. 增加对 `JPEG` 和 `HEIC` 图片格式的支持
|
||||
2. 支持 `SOCKS` 代理
|
||||
2. 优化 `headers` 处理逻辑
|
||||
3. 支持 `SOCKS` 代理
|
||||
|
||||
*****
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user