ESC
开源 5 分钟阅读

ruyiJS:使用真正的迷你AI无头浏览器从Python运行任何网站,绕过任何安全反爬虫,获取你想要的数据和令牌

ruyiJS是一个轻量级无头浏览器,集成Firefox的SpiderMonkey引擎,允许Python直接执行网站JavaScript,绕过反爬虫验证,适用于数据采集和逆向工程。

来源:GitHub

🦊 ruyiJS

从Python运行任何网站的JavaScript——使用真正的Firefox引擎。

新一代极简浏览器,专为AI驱动的自动化而构建。

真实的Firefox JavaScript引擎和网络栈,无窗口无渲染器——专用于网页抓取、JS逆向工程、数据采集和绕过机器人检测。

PyPI Python License Windows LinuxDO

Sponsored by

FastAIToken

安装 · 特性 · 验证系统 · 示例 · 常见问题 · 联系 · LinuxDO · [英文] · 简体中文


ruyiJS适合你吗?

无头Chrome和Playwright给你一个完整的浏览器:一个GPU渲染、窗口管理、内存密集的进程,而反机器人供应商已经花了多年时间来检测它。ruyiJS采取了相反的路径——它只嵌入对自动化重要的Firefox内部组件,而其余的丢弃:

  • 真正的引擎,而非模拟。 真正的SpiderMonkey(Firefox 158)和Necko网络栈以与Firefox完全相同的方式执行网站的JavaScript、挑战、签名和指纹。
  • 真正的无头。 无窗口、无布局、无渲染器。一个纯JavaScript + Web API环境,启动快速且保持轻量。
  • 隔离且可复现。 每个Context都是自己的进程,拥有持久的JavaScript世界和自己的代理,因此会话不会相互泄漏。
  • 需要时离线。 自己提供脚本和响应,并重放整个捕获的流程,无需网络。

如果你抓取、逆向工程网页JavaScript或在挑战后面采集数据,它适合你。如果普通HTTP客户端已经能获取你的页面,你就不需要它。

运行于Windows x64,需要Python 3.10+(已在Python 3.14上验证)。wheel捆绑了固定的原生运行时,因此无需额外下载。


📦 安装

python -m pip install ruyijs

要求: Windows x64上的Python 3.10+(已在Python 3.10 – 3.14上验证)。

wheel附带了SHA256固定的SpiderMonkey + Necko运行时(~42 MB)。本地脚本在安装后即可离线运行——无需浏览器下载,无需外部依赖。

升级:

python -m pip install --upgrade ruyijs

验证安装:

import ruyijs
print(ruyijs.__version__)   # 0.1.6

🚀 快速入门

1 · 打开一个上下文并运行JavaScript。 变量和函数在同一上下文中跨eval调用持久存在。

from ruyijs import Context

with Context() as context:
    context.eval("let count = 40")
    print(context.eval("count += 2"))        # 42
    print(context.eval("navigator.userAgent"))

3 · 对准一个真实目标。 配置环境,加载页面,让网站自己的JavaScript生成它要求的任何令牌。

with Context(proxy="http://127.0.0.1:7890") as context:
    context.configure_fingerprint({
        "navigator": {"language": "zh-CN", "hardwareConcurrency": 8},
        "locale": {"timezone": "Asia/Shanghai"},
    })
    context.load_page("https://target.example/", html)
    token = context.eval("window.__sign(payload)")   # 运行页面的签名器
    print(token)

🏗️ 它们如何组合在一起

Python ──► ruyiJS上下文(隔离进程) ──► 目标网站 ├─ SpiderMonkey —— Firefox 158 JS引擎 ├─ 38个浏览器上下文 —— DOM · Canvas · Workers · iframes · … └─ Necko —— HTTP/1.1 · 2 · 3,每个上下文代理

你的Python代码驱动一个Context。在其内部,真正的SpiderMonkey引擎针对真实的DOM和38个受限的浏览器子系统运行页面的脚本,同时页面内的fetch/XHR通过Necko传输。实现位于src(域、应用程序和每个浏览器子系统)和python/ruyijs/(绑定)。


✨ 特性

运行网站的JavaScript

在持久上下文中执行脚本,加载包含iframes和经典脚本的真实HTML,并查询结果DOM。指向实时JS对象的引用以JSObject / JSFunction形式返回,你可以从Python调用它们。

能力如何
执行JS,保持状态context.eval(src) —— 变量和函数持久存在
获取可调用的函数context.eval(src, to_py=False) → JSFunction
加载页面context.load_page(url, html) —— 相对URL针对url解析
顶级导航context.navigate(url) —— 无Referer,Sec-Fetch-Site: none
查询DOMcontext.eval("document.querySelector('#x').textContent")
with Context() as context:
    context.set("config", {"offset": 2})
    add = context.eval("(value) => value + config.offset", to_py=False)
    print(add(40))  # 42

配置浏览器环境

通过一个验证过的配置文件表面设置Navigator、Screen、视口、时区和区域设置。在第一个页面脚本运行之前提交它。

with Context() as context:
    context.configure_fingerprint({
        "navigator": {"language": "zh-CN", "hardwareConcurrency": 8},
        "screen": {"width": 1920, "height": 1080},
        "viewport": {"width": 1280, "height": 720},
        "locale": {"timezone": "Asia/Shanghai"},
    })
    print(context.eval("[navigator.language, screen.width]"))  # ['zh-CN', 1920]

通过Necko实现原生网络

页面内的fetch和XHR通过代理(作用域到上下文)进行真实的HTTP/1.1、2和3请求。你自己用put_resource()提供响应,以离线重放整个捕获的流程。用net_log()检查每个请求。

with Context(proxy="http://127.0.0.1:7890", timeout=30) as context:
    context.load_page("https://example.com/", "")
    context.eval("globalThis.r = null; fetch('/api').then(x => x.json()).then(v => r = v)")
    context.advance(25)               # 驱动事件循环直到它稳定
    print(context.eval("r"))

Python ↔ JavaScript桥接

传入数据,获取可调用的JS函数,并向运行中的脚本暴露Python函数。包括Workers、Service Workers和iframes。

with Context() as context:
    context.expose(lambda a, b: a + b, "add")
    print(context.eval("add(20, 22)"))  # 42

确定时钟

用逻辑时钟驱动定时器以实现完美可复现的运行,或用系统时钟进行实时工作。主机显式推进时间。

with Context() as context:
    context.configure_clock("logical", epoch_ms=1700000000000)
    context.eval("globalThis.result = 0; setTimeout(() => { result = 42 }, 10)")
    context.advance(10)
    print(context.eval("result"))  # 42

错误和日志

JavaScript异常以JSError形式出现,包含名称、消息和堆栈。console_log()和net_log()返回捕获的控制台和网络记录。

from ruyijs import Context, JSError

with Context(timeout=10) as context:
    try:
        context.eval("throw new TypeError('bad input')", filename="demo.js")
    except JSError as error:
        print(error.name, error.message)  # TypeError bad input
        print(error.stack)

🛡️ 它击败的验证系统

每个示例都驱动网站自己的JavaScript生成它要求的参数,然后端到端地完成流程。所有示例都在包中附带运行:python -m ruyijs.examples <name>。

系统类别示例
瑞数 Ruishu 5/6动态VM / 页面保护fangdi · cebwm
极验 Geetest滑块 / 一键geetest
腾讯天御 Tencent Captcha无感+滑块tianyu
数美 Shumei滑块shumei
网易易盾 NetEase Yidun智能检查yidun
Arkose Labs + iovation企业风险 / 设备expedia-taap
Akamai Bot Manager 3.xsensor_data + sbsd挑战akamai
阿里 234 / fireyejsJSVMP字节码VM / bx-ua令牌ali234
CreepJS指纹审计——通过每个部分creepjs

完整的生产数据采集流程:BOSS直聘,今日头条 Toutiao,抖音 Douyin,小红书 RedNote,Google,Expedia TAAP。

🔒 严格禁止任何非法用途。 ruyiJS仅提供用于研究新一代AI浏览器。实时结果取决于当前网络状况和每个站点的当前响应。


🧪 示例

示例在包内附带——无需克隆仓库:

python -m ruyijs.examples                      # 列出每个示例及其安装路径
python -m ruyijs.examples google --query python --pages 1
python -m ruyijs.examples boss --query ai --city 101210100
python -m ruyijs.examples fangdi               # 网上房地产 (Ruishu 6)
python -m ruyijs.examples ...

cebwm –pages 3 # 光大理财 (custom Ruishu) python -m ruyijs.examples toutiao –pages 3 # 今日头条 python -m ruyijs.examples xhs –pages 3 # 小红书 / RedNote home feed python -m ruyijs.examples geetest # 极验 one-click python -m ruyijs.examples yidun # 网易易盾 python -m ruyijs.examples shumei # 数美 slider python -m ruyijs.examples tianyu # 腾讯天御 python -m ruyijs.examples akamai # Akamai Bot Manager 3.x python -m ruyijs.examples ali234 # 阿里 234 / 淘宝 bx-ua


Every example supports `--direct` (direct connection) and `--proxy http://127.0.0.1:7890`. Add `--help` after a name for all options, and `--output result.json` to save results. Each example directory ships its own README.

## 📚 Documentation & API

| | |
| :-- | :-- |
| **`Context.eval` / `set` / `expose`** | Execute JS, pass data in, expose Python callbacks |
| **`load_page` / `navigate` / `put_resource`** | Load HTML, top-level navigation, serve resources offline |
| **`configure_fingerprint` / `configure_environment`** | Navigator, Screen, viewport, timezone, locale |
| **`configure_clock` / `advance` / `tick`** | Logical vs. system clock, drive the event loop |
| **`JSError` / `console_log` / `net_log`** | Errors as exceptions, console and network records |
| **`JSObject` / `JSFunction` / `get_runtime_path`** | Live JS handles, bundled-runtime path |

## 📏 Scope & limitations

ruyiJS provides JavaScript execution and a broad Web API environment on **Windows x64**. It has **no browser window and no full page layout or rendering** — it is a tool for automation, analysis, and research. Use it in compliance with the terms of service of any site you interact with and with applicable law.

**Related:** [**ruyiHttp**](https://gitee.com/losenine888/ruyiHttp) — a Requests-style Python HTTP library built on Firefox's native networking components.

## ❓ FAQ / Troubleshooting

<details>
<summary><b>What Python versions are supported?</b></summary>

Python 3.10 and above on Windows x64 (64-bit). Tested up to Python 3.14.
</details>

<details>
<summary><b>Does it work on macOS or Linux?</b></summary>

Not yet — currently Windows x64 only. Cross-platform support is planned.
</details>

<details>
<summary><b>Do I need to download a browser?</b></summary>

No. The wheel bundles the pinned SpiderMonkey + Necko runtime. Everything works offline right after `pip install ruyijs`.
</details>

<details>
<summary><b>Context hangs or doesn't respond</b></summary>

- Make sure you use the `with` statement (`with Context() as ctx:`) so the process is cleaned up properly.
- If using a proxy, verify it is reachable: `context = Context(proxy="http://127.0.0.1:7890")`.
- Increase the timeout: `Context(timeout=60)`.
- On Wine, upgrade to ≥ 0.1.5 which fixes a known navigate deadlock ([issue #1](https://github.com/martinkeith700/ruyiJS/issues/1)).
</details>

<details>
<summary><b>JSError: script error</b></summary>

The site's JavaScript threw an exception. Inspect `error.name`, `error.message`, and `error.stack` to locate the cause. If the page relies on APIs not yet implemented, the stack trace will point to the missing call.
</details>

<details>
<summary><b>How do I use a proxy?</b></summary>

```python
with Context(proxy="http://127.0.0.1:7890") as ctx:
    ctx.navigate("https://example.com/")

HTTP, HTTPS, and SOCKS5 proxies are supported per-context.

How do I run examples?
python -m ruyijs.examples              # list all examples
python -m ruyijs.examples google --query python
python -m ruyijs.examples akamai --proxy http://127.0.0.1:7890

💬 Contact

Questions, permission requests, commercial licensing, or just to talk shop — add the author on WeChat, or scan to join the discussion group.

WeChat QR — 如意
WeChat: 如意
Group — AI 浏览器过检测交流群
Group: AI 浏览器过检测交流群

The group QR refreshes periodically; if it has expired, add the author on WeChat (如意) for an invite.

📄 License

Licensed under the Mozilla Public License 2.0. See NOTICE for third-party attributions.

📌 As a courtesy: for redistribution and commercial use, please obtain the author’s permission — add the author on WeChat (ID: 如意) or open an issue on GitHub.

If ruyiJS saved you from reimplementing a browser, a ⭐ helps others find it.