fix
This commit is contained in:
parent
1627d3cf89
commit
837ae3e01b
39
server.py
39
server.py
@ -12,6 +12,9 @@ monkey.patch_all()
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
A1 = ""
|
A1 = ""
|
||||||
|
# 确保在模块级别声明全局变量
|
||||||
|
browser_context = None
|
||||||
|
context_page = None
|
||||||
|
|
||||||
|
|
||||||
def get_context_page(instance, stealth_js_path):
|
def get_context_page(instance, stealth_js_path):
|
||||||
@ -42,25 +45,25 @@ print("跳转小红书首页成功,等待调用")
|
|||||||
|
|
||||||
|
|
||||||
def sign(uri, data, a1, web_session):
|
def sign(uri, data, a1, web_session):
|
||||||
try:
|
global browser_context, context_page # 声明全局变量
|
||||||
# Ensure the page is still valid and reload if necessary
|
try:
|
||||||
if context_page.is_closed():
|
# 确保页面仍然有效,如果页面已关闭则重新初始化
|
||||||
global browser_context, context_page
|
if context_page is None or context_page.is_closed():
|
||||||
browser_context, context_page = get_context_page(playwright, stealth_js_path)
|
browser_context, context_page = get_context_page(playwright, stealth_js_path)
|
||||||
context_page.goto("https://www.xiaohongshu.com")
|
context_page.goto("https://www.xiaohongshu.com")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
context_page.reload()
|
context_page.reload()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Evaluate the JavaScript function
|
# 执行 JavaScript 函数
|
||||||
encrypt_params = context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
|
encrypt_params = context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
|
||||||
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"])
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error during sign operation: {e}")
|
print(f"Error during sign operation: {e}")
|
||||||
return {"error": str(e)}
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/sign", methods=["POST"])
|
@app.route("/sign", methods=["POST"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user