first
This commit is contained in:
@@ -3,7 +3,6 @@ import requests, re, json, base64
|
||||
import io, os, random
|
||||
import time, cv2, json
|
||||
from PIL import Image
|
||||
from functools import partial
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
@@ -13,7 +12,6 @@ from detect.module.use_ua import randomUA
|
||||
from detect.module.gap import quekou
|
||||
import subprocess
|
||||
|
||||
subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')
|
||||
import execjs
|
||||
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ import json # JSON数据处理
|
||||
import os # 操作系统接口
|
||||
import pickle # 序列化反序列化
|
||||
import random # 随机数生成
|
||||
import shutil
|
||||
import subprocess # 子进程管理
|
||||
import time # 时间处理
|
||||
from functools import partial
|
||||
|
||||
# 导入第三方库
|
||||
import requests # HTTP请求库
|
||||
@@ -33,11 +33,17 @@ from requests.cookies import RequestsCookieJar # Cookie管理
|
||||
# super().__init__(*args, **kwargs) # 调用父类初始化方法
|
||||
#
|
||||
#
|
||||
# subprocess.Popen = MySubprocessPopen # 替换subprocess.Popen为自定义类
|
||||
os.environ["EXECJS_RUNTIME"] = "Node" # 设置JavaScript运行时环境为Node.js
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
subprocess.Popen = partial(subprocess.Popen, encoding='utf-8', startupinfo=startupinfo)
|
||||
_ORIGINAL_POPEN = subprocess.Popen
|
||||
|
||||
|
||||
def create_subprocess(*args, **kwargs):
|
||||
kwargs.setdefault("encoding", "utf-8")
|
||||
if hasattr(subprocess, "STARTUPINFO") and hasattr(subprocess, "STARTF_USESHOWWINDOW"):
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
kwargs.setdefault("startupinfo", startupinfo)
|
||||
return _ORIGINAL_POPEN(*args, **kwargs)
|
||||
|
||||
|
||||
def resolve_node_executable() -> str:
|
||||
@@ -46,6 +52,19 @@ def resolve_node_executable() -> str:
|
||||
bundled_node = os.path.join(project_dir, "tools", "node-v20.19.4-win-x64", "node.exe")
|
||||
if os.path.exists(bundled_node):
|
||||
return bundled_node
|
||||
detected = shutil.which("node")
|
||||
if detected:
|
||||
return detected
|
||||
fallback_candidates = [
|
||||
"/usr/bin/node",
|
||||
"/usr/local/bin/node",
|
||||
os.path.expanduser("~/.nvm/versions/node/current/bin/node"),
|
||||
os.path.expanduser("~/.nvm/versions/node/v20.20.2/bin/node"),
|
||||
"/root/.nvm/versions/node/v20.20.2/bin/node",
|
||||
]
|
||||
for candidate in fallback_candidates:
|
||||
if os.path.exists(candidate):
|
||||
return candidate
|
||||
return "node"
|
||||
|
||||
def calculate_seed(t: int) -> str: # 计算验证码种子值
|
||||
@@ -195,7 +214,7 @@ class JC(object): # 聚查网API封装类
|
||||
return False, f"缺少签名脚本: {jsFile_path}" # 返回失败
|
||||
|
||||
try: # 尝试执行Node.js脚本
|
||||
with subprocess.Popen( # 创建子进程
|
||||
with create_subprocess( # 创建子进程
|
||||
[resolve_node_executable(), jsFile_path], # 执行node命令
|
||||
stdin=subprocess.PIPE, # 标准输入管道
|
||||
stdout=subprocess.PIPE, # 标准输出管道
|
||||
|
||||
@@ -14,9 +14,9 @@ import json # JSON处理模块
|
||||
import os # 操作系统接口模块
|
||||
import pickle # 序列化模块
|
||||
import random # 随机数生成模块
|
||||
import shutil
|
||||
import subprocess # 子进程管理模块
|
||||
import time # 时间处理模块
|
||||
from functools import partial
|
||||
from typing import Optional, Tuple, Dict, List, Any # 类型提示
|
||||
|
||||
import requests # HTTP请求库
|
||||
@@ -34,17 +34,25 @@ SLIDE_OFFSET = 290 # 滑块偏移量
|
||||
SLIDE_DURATION = 611 # 滑动持续时间
|
||||
|
||||
|
||||
class MySubprocessPopen(subprocess.Popen): # 自定义子进程类
|
||||
_ORIGINAL_POPEN = subprocess.Popen
|
||||
|
||||
|
||||
class MySubprocessPopen(_ORIGINAL_POPEN): # 自定义子进程类
|
||||
def __init__(self, *args, **kwargs): # 初始化方法
|
||||
kwargs['encoding'] = "UTF-8" # 设置编码为UTF-8
|
||||
super().__init__(*args, **kwargs) # 调用父类初始化
|
||||
|
||||
|
||||
subprocess.Popen = MySubprocessPopen # 替换默认的Popen类
|
||||
os.environ["EXECJS_RUNTIME"] = "Node" # 设置JavaScript运行时为Node.js
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
subprocess.Popen = partial(subprocess.Popen, encoding='utf-8', startupinfo=startupinfo)
|
||||
|
||||
|
||||
def create_subprocess(*args, **kwargs):
|
||||
kwargs.setdefault("encoding", "utf-8")
|
||||
if hasattr(subprocess, "STARTUPINFO") and hasattr(subprocess, "STARTF_USESHOWWINDOW"):
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
kwargs.setdefault("startupinfo", startupinfo)
|
||||
return MySubprocessPopen(*args, **kwargs)
|
||||
|
||||
|
||||
def resolve_node_executable() -> str:
|
||||
@@ -53,6 +61,19 @@ def resolve_node_executable() -> str:
|
||||
bundled_node = os.path.join(project_dir, "tools", "node-v20.19.4-win-x64", "node.exe")
|
||||
if os.path.exists(bundled_node):
|
||||
return bundled_node
|
||||
detected = shutil.which("node")
|
||||
if detected:
|
||||
return detected
|
||||
fallback_candidates = [
|
||||
"/usr/bin/node",
|
||||
"/usr/local/bin/node",
|
||||
os.path.expanduser("~/.nvm/versions/node/current/bin/node"),
|
||||
os.path.expanduser("~/.nvm/versions/node/v20.20.2/bin/node"),
|
||||
"/root/.nvm/versions/node/v20.20.2/bin/node",
|
||||
]
|
||||
for candidate in fallback_candidates:
|
||||
if os.path.exists(candidate):
|
||||
return candidate
|
||||
return "node"
|
||||
|
||||
def calculate_seed(t: int) -> str: # 计算验证码种子值
|
||||
@@ -230,7 +251,7 @@ class JM(object): # 聚名网API封装类
|
||||
return False, f"缺少签名脚本: {jsFile_path}" # 返回失败
|
||||
|
||||
try: # 异常处理
|
||||
with subprocess.Popen( # 执行Node.js脚本
|
||||
with create_subprocess( # 执行Node.js脚本
|
||||
[resolve_node_executable(), jsFile_path], # 命令和参数
|
||||
stdin=subprocess.PIPE, # 标准输入
|
||||
stdout=subprocess.PIPE, # 标准输出
|
||||
|
||||
Reference in New Issue
Block a user