全球动态代理 · 静态住宅代理 · 极高质量 · 包月不限量 · 学员低价 · 联系如意进行免费测试 · 欢迎公司及学员采购 · 另有任何海外数据采集需求,随时联系 · 商务合作微信:Charleval
Automation / 隐私模式
浏览器能力

RuyiPage 隐私模式

隐私模式适合一次性会话、减少浏览历史残留,重点要区分它和默认临时 profile 不是一回事。

两种开启方式

python 通过 FirefoxOptions
from ruyipage import FirefoxOptions, FirefoxPage

opts = FirefoxOptions()
opts.private_mode(True)

page = FirefoxPage(opts)
page.get("https://www.example.com")
page.quit()
python 通过 launch()
from ruyipage import launch

page = launch(private=True)
page.get("https://www.example.com")
page.quit()

使用要点

  • private=True 会为 Firefox 增加 -private 启动参数。
  • 这和默认的临时 profile 不相同,含义不要混淆。
  • 如果你只是不想复用历史数据,不传 user_dir 也可以形成一次性会话。
  • 如果你明确要走 Firefox 私密浏览语义,再用 private 模式。

相关示例源码

2 个示例 ▶ 点击展开

隐私模式快速开始

quickstart_private_mode.py

展示 Firefox 私密浏览模式的两种启动方式,以及它与临时 profile 的区别。

GitHub 仓库 查看仓库源码 FirefoxOptionsopts.private_modeFirefoxPagelaunch(private=True)page.getpage.quit
  • 通过 FirefoxOptions 开启私密浏览
  • 通过 launch(private=True) 快速启动
  • 理解私密模式与临时用户目录的区别
  • 验证私密模式下的页面访问流程

一步上手:最少代码完成访问与读取

examples/01_quickstart.py

最短可运行的 hello-world 级别示例,适合验证环境和建立第一层心智模型。

GitHub 仓库 查看仓库源码 launchpage.getpage.waitpage.titlepage.eleele.textpage.quit
  • 用 launch() 启动 Firefox
  • 访问网页并等待页面稳定
  • 读取标题和 H1 文本
  • 演示最短退出流程

源码文件:app/content/ruyipage_examples/01_quickstart.py · 仓库:01_quickstart.py

python 注释版
# =============================
# RuyiPage 示例注释版
# 标题: 一步上手:最少代码完成访问与读取
# 说明: 最短可运行的 hello-world 级别示例,适合验证环境和建立第一层心智模型。
# 你会学到:
#   1. 用 launch() 启动 Firefox
#   2. 访问网页并等待页面稳定
#   3. 读取标题和 H1 文本
#   4. 演示最短退出流程
# 相关 API: launch, page.get, page.wait, page.title, page.ele, ele.text, page.quit
# =============================

# -*- coding: utf-8 -*-
"""
示例01: 一步上手

面向新手:最少代码完成一次页面访问与元素交互。
"""

import io
import sys


if sys.platform == "win32":
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")


from ruyipage import launch


def quickstart_demo():
    print("=" * 60)
    print("示例01: 一步上手")
    print("=" * 60)

    page = launch(headless=False)

    try:
        page.get("https://example.com")
        page.wait(1)
        print(f"标题: {page.title}")

        h1 = page.ele("tag:h1")
        print(f"H1文本: {h1.text}")

        print("\n✓ 快速上手完成")
    finally:
        page.wait(1)
        page.quit()


if __name__ == "__main__":
    quickstart_demo()