Spaces:
Runtime error
Runtime error
File size: 5,257 Bytes
ce89ece 1dd5f80 59b4997 5e0325c 59b4997 1a42b23 1dd5f80 ed77551 5e0325c 1dd5f80 5e0325c 3cdf80d 1dd5f80 5e0325c 59b4997 5e0325c 4d8cf41 5e0325c 3cdf80d 59b4997 1a42b23 3cdf80d 1a42b23 ce89ece 3cdf80d ce89ece 3cdf80d ce89ece 3cdf80d ce89ece 3cdf80d ce89ece 3cdf80d ce89ece 1a42b23 ce89ece 3cdf80d 1a42b23 3cdf80d 59b4997 1a42b23 5e0325c 5ebf712 1a42b23 ce89ece 1a42b23 ce89ece 064e3bb ce89ece 064e3bb 1a42b23 ce89ece 1a42b23 ce89ece 1a42b23 ce89ece 1a42b23 59b4997 1dd5f80 59b4997 1dd5f80 e65cca5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # proxy.py (全量替换云端 - 彻底过 Google 浏览器安全风控版)
import os
import time
import asyncio
from huggingface_hub import HfApi, snapshot_download
import websockets
from playwright.async_api import async_playwright
DATASET_ID = "sdfgrtg/idx-profile-storage"
CLOUD_DATA_DIR = "/app/data"
CLOUD_PROFILE_DIR = "/app/data/chrome_profile"
HTTP_PORT = 7860
HF_TOKEN = os.environ.get("HF_TOKEN")
GLOBAL_PAGE = None
def sync_from_dataset():
if not HF_TOKEN: return
try:
snapshot_download(repo_id=DATASET_ID, repo_type="dataset", local_dir=CLOUD_DATA_DIR, token=HF_TOKEN, ignore_patterns=[".git*", "README.md"])
print("✅ 凭证同步下载成功!")
except Exception as e:
print(f"ℹ️ 下载提示: {e}")
async def ws_handler(websocket, path):
global GLOBAL_PAGE
print("🔌 影子控制链路切入...")
try:
async for message in websocket:
cmd = message.decode('utf-8', errors='ignore') if isinstance(message, bytes) else str(message)
if cmd.startswith("http"):
print(f"🌐 正在导航至: {cmd}")
await GLOBAL_PAGE.goto(cmd, timeout=90000, wait_until="networkidle")
await asyncio.sleep(5)
screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
await websocket.send(screenshot_bytes)
elif cmd.startswith("ACTION_EMAIL:"):
email = cmd.split("ACTION_EMAIL:")[1]
print(f"⌨️ 正在输入邮箱...")
# 模拟真人打字速度,防止被识别为机械输入
await GLOBAL_PAGE.locator('input[type="email"]').click()
await GLOBAL_PAGE.locator('input[type="email"]').type(email, delay=100)
await asyncio.sleep(1)
await GLOBAL_PAGE.locator('#identifierNext').click()
await asyncio.sleep(6)
screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
await websocket.send(screenshot_bytes)
elif cmd.startswith("ACTION_PASSWORD:"):
password = cmd.split("ACTION_PASSWORD:")[1]
print(f"⌨️ 正在输入密码...")
await GLOBAL_PAGE.locator('input[type="password"]').click()
await GLOBAL_PAGE.locator('input[type="password"]').type(password, delay=120)
await asyncio.sleep(1)
await GLOBAL_PAGE.locator('#passwordNext').click()
await asyncio.sleep(10)
screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
await websocket.send(screenshot_bytes)
elif cmd.startswith("ACTION_CODE:"):
code = cmd.split("ACTION_CODE:")[1]
print(f"⌨️ 正在处理验证码...")
try:
await GLOBAL_PAGE.locator('input[id="idvanyphoneverifycode"]').click()
await GLOBAL_PAGE.locator('input[id="idvanyphoneverifycode"]').type(code, delay=80)
await asyncio.sleep(1)
await GLOBAL_PAGE.locator('#idvanyphoneverifynext').click()
except:
pass
await asyncio.sleep(10)
screenshot_bytes = await GLOBAL_PAGE.screenshot(type="png")
await websocket.send(screenshot_bytes)
except Exception as e:
print(f"ℹ️ 链路结束: {e}")
async def main_async():
global GLOBAL_PAGE
sync_from_dataset()
playwright_context = await async_playwright().start()
# 💡 核心改良:注入完美的真人全套浏览器指纹环境,洗白机房特征
browser_context = await playwright_context.chromium.launch_persistent_context(
user_data_dir=CLOUD_PROFILE_DIR,
headless=True,
accept_downloads=True,
# 伪装成标准的 Windows 桌面版 Chrome 浏览器 User-Agent
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
locale="zh-CN,zh;q=0.9,en;q=0.8", # 注入正常的语言链
timezone_id="Asia/Shanghai", # 注入时区
args=[
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
# 抹除 WebDriver 自动化标记
"--disable-blink-features=AutomationControlled",
# 允许混入正常的机器特征
"--lang=zh-CN",
"--password-store=basic"
]
)
# 利用底层脚本进一步抹除 window.navigator.webdriver 属性,做到绝对伪装
GLOBAL_PAGE = await browser_context.new_page()
await GLOBAL_PAGE.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
await GLOBAL_PAGE.set_viewport_size({"width": 1280, "height": 800})
print(f"🟢 真人伪装升级控制网桥已就绪...")
async with websockets.serve(ws_handler, "0.0.0.0", HTTP_PORT):
while True:
await asyncio.sleep(3600)
if __name__ == "__main__":
try:
asyncio.run(main_async())
except KeyboardInterrupt:
print("🚪 关闭") |