fix a1 is mani browser
This commit is contained in:
parent
ea8632bfd6
commit
e591d2cb7c
14
app.py
14
app.py
@ -61,7 +61,13 @@ async def initialize_playwright():
|
||||
await loginModal.evaluate("el => el.click()")
|
||||
print("登录弹窗已关闭")
|
||||
print("跳转小红书首页成功,等待调用")
|
||||
|
||||
async def show_cookies():
|
||||
global browser_context, context_page, global_a1 # 声明全局变量
|
||||
cookies = await browser_context.cookies()
|
||||
for cookie in cookies:
|
||||
if cookie["name"] == "a1":
|
||||
global_a1 = cookie["value"]
|
||||
print("当前浏览器 cookie 中 a1 值为:" + cookie["value"] + ",请将需要使用的 a1 设置成一样方可签名成功")
|
||||
|
||||
async def setCookie(a1: str) -> Dict[str, Any]:
|
||||
global browser_context, context_page # 声明全局变量
|
||||
@ -114,6 +120,7 @@ async def reload_browser():
|
||||
await context_page.reload()
|
||||
await asyncio.sleep(1)
|
||||
print("浏览器已重新加载")
|
||||
show_cookies()
|
||||
except Exception as e:
|
||||
print(f"Error during reload_browser operation: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@ -129,8 +136,8 @@ async def sign(uri: str, data: Dict[str, Any], a1: str, web_session: str) -> Dic
|
||||
await context_page.reload()
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if a1 != global_a1:
|
||||
await setCookie(a1) # Ensure setCookie is awaited properly
|
||||
# if a1 != global_a1:
|
||||
# await setCookie(a1) # Ensure setCookie is awaited properly
|
||||
|
||||
# 执行 JavaScript 函数
|
||||
b1 = await context_page.evaluate("() => localStorage.getItem('b1')")
|
||||
@ -144,6 +151,7 @@ async def sign(uri: str, data: Dict[str, Any], a1: str, web_session: str) -> Dic
|
||||
"x-s": encrypt_params["X-s"],
|
||||
"x-t": str(encrypt_params["X-t"]),
|
||||
"b1": b1,
|
||||
"a1": global_a1,
|
||||
"b1b1": b1b1,
|
||||
}
|
||||
except Exception as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user