学习fastapi
This commit is contained in:
parent
774b843d27
commit
2718d24977
8
app.py
8
app.py
@ -68,7 +68,7 @@ async def setCookie(a1: str) -> Dict[str, Any]:
|
|||||||
global global_a1
|
global global_a1
|
||||||
try:
|
try:
|
||||||
# 确保页面仍然有效,如果页面已关闭则重新初始化
|
# 确保页面仍然有效,如果页面已关闭则重新初始化
|
||||||
if context_page is None or await context_page.is_closed():
|
if context_page is None or context_page.is_closed():
|
||||||
browser_context, context_page = await get_context_page(playwright_instance, "stealth.min.js")
|
browser_context, context_page = await get_context_page(playwright_instance, "stealth.min.js")
|
||||||
await context_page.goto("https://www.xiaohongshu.com")
|
await context_page.goto("https://www.xiaohongshu.com")
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
@ -102,7 +102,7 @@ async def sign(uri: str, data: Dict[str, Any], a1: str, web_session: str) -> Dic
|
|||||||
global global_a1
|
global global_a1
|
||||||
try:
|
try:
|
||||||
# 确保页面仍然有效,如果页面已关闭则重新初始化
|
# 确保页面仍然有效,如果页面已关闭则重新初始化
|
||||||
if context_page is None or await context_page.is_closed():
|
if context_page is None or context_page.is_closed():
|
||||||
browser_context, context_page = await get_context_page(playwright_instance, "stealth.min.js")
|
browser_context, context_page = await get_context_page(playwright_instance, "stealth.min.js")
|
||||||
await context_page.goto("https://www.xiaohongshu.com")
|
await context_page.goto("https://www.xiaohongshu.com")
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
@ -110,12 +110,14 @@ async def sign(uri: str, data: Dict[str, Any], a1: str, web_session: str) -> Dic
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
if a1 != global_a1:
|
if a1 != global_a1:
|
||||||
await setCookie(a1)
|
await setCookie(a1) # Ensure setCookie is awaited properly
|
||||||
# 执行 JavaScript 函数
|
# 执行 JavaScript 函数
|
||||||
# localStorage.getItem("b1")
|
# localStorage.getItem("b1")
|
||||||
b1 = await context_page.evaluate("() => localStorage.getItem('b1')")
|
b1 = await context_page.evaluate("() => localStorage.getItem('b1')")
|
||||||
b1b1 = await context_page.evaluate("() => localStorage.getItem('b1b1')")
|
b1b1 = await context_page.evaluate("() => localStorage.getItem('b1b1')")
|
||||||
encrypt_params = await context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
|
encrypt_params = await context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
|
||||||
|
if not encrypt_params or not isinstance(encrypt_params, dict):
|
||||||
|
raise HTTPException(status_code=500, detail="Failed to retrieve encryption parameters")
|
||||||
return {
|
return {
|
||||||
"x-s": encrypt_params["X-s"],
|
"x-s": encrypt_params["X-s"],
|
||||||
"x-t": str(encrypt_params["X-t"]),
|
"x-t": str(encrypt_params["X-t"]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user