This commit is contained in:
熊潇 2025-05-01 19:28:19 +08:00
parent 638e98b0e9
commit 1627d3cf89

View File

@ -42,11 +42,25 @@ print("跳转小红书首页成功,等待调用")
def sign(uri, data, a1, web_session):
try:
# Ensure the page is still valid and reload if necessary
if context_page.is_closed():
global browser_context, context_page
browser_context, context_page = get_context_page(playwright, stealth_js_path)
context_page.goto("https://www.xiaohongshu.com")
time.sleep(5)
context_page.reload()
time.sleep(1)
# Evaluate the JavaScript function
encrypt_params = context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
return {
"x-s": encrypt_params["X-s"],
"x-t": str(encrypt_params["X-t"])
}
except Exception as e:
print(f"Error during sign operation: {e}")
return {"error": str(e)}
@app.route("/sign", methods=["POST"])