Spaces:
Runtime error
Runtime error
Download proxy.py from sdfgrtg/ggfpp: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/spaces/sdfgrtg/ggfpp/resolve/main/proxy.py
- Command line
-
hf download hf://spaces/sdfgrtg/ggfpp/proxy.py
-
curl -L -o proxy.py https://huggingface.co/spaces/sdfgrtg/ggfpp/resolve/main/proxy.py
5.26 kB
| # 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("🚪 关闭") |