FirefoxOptions
返回: FirefoxOptionsFirefoxOptions()创建启动配置对象,传给 FirefoxPage(opts) 使用。
常见坑
- 配置对象本身不启动浏览器,需配合 FirefoxPage 使用。
相关示例
FirefoxOptions 是启动配置的总入口。浏览器路径、用户目录、代理、fpfile、隐私模式等所有配置都从这里设置。
FirefoxOptions()创建启动配置对象,传给 FirefoxPage(opts) 使用。
opts.set_browser_path(path)指定 Firefox 可执行文件路径。使用指纹浏览器时必须设置。
| 参数 | 说明 |
|---|---|
| path | Firefox 或指纹浏览器的绝对路径。 |
opts.set_user_dir(path)指定用户数据目录(profile)。复用登录态、Cookie 和扩展。
| 参数 | 说明 |
|---|---|
| path | 目录路径,不存在会自动创建。 |
opts.set_fpfile(path)加载指纹配置文件。含代理认证、浏览器指纹等底层配置。
| 参数 | 说明 |
|---|---|
| path | fpfile 文件路径,格式为 key:value 逐行。 |
opts.set_proxy("http://host:port")设置 HTTP 代理地址。
| 参数 | 说明 |
|---|---|
| proxy | 代理地址,格式 http://host:port。 |
opts.headless(True)开启无界面模式。
| 参数 | 说明 |
|---|---|
| enable | True 无界面 / False 有界面。 |
opts.private_mode(True)开启隐私浏览模式。
| 参数 | 说明 |
|---|---|
| enable | True 开启。 |
from ruyipage import FirefoxOptions, FirefoxPage
opts = FirefoxOptions()
opts.set_browser_path(r"C:\Program Files\Mozilla Firefox\firefox.exe")
opts.set_user_dir(r"D:\ruyipage_userdir")
page = FirefoxPage(opts)
page.get("https://www.example.com")
page.quit()from ruyipage import FirefoxOptions, FirefoxPage
opts = FirefoxOptions()
opts.set_browser_path(r"C:\Firefox\firefox.exe")
opts.set_fpfile(r"C:\Firefox\profile1.txt")
opts.set_proxy("http://your-proxy-host:8080")
page = FirefoxPage(opts)
page.get("https://www.browserscan.net/zh")
page.quit()| 场景 | 用 launch() | 用 FirefoxOptions |
|---|---|---|
| 简单测试 | 推荐 | 不需要 |
| 指定浏览器路径 | browser_path 参数 | set_browser_path() |
| 复用登录态 | user_dir 参数 | set_user_dir() |
| 指纹浏览器 | ❌ 不支持 fpfile | set_fpfile() ✅ |
| 代理 | ❌ 不支持 | set_proxy() ✅ |
| 隐私模式 | private=True | private_mode(True) |
展示 Firefox 私密浏览模式的两种启动方式,以及它与临时 profile 的区别。
演示如何把 Firefox 指纹浏览器、指纹文件、地理位置、语言和请求头一起接入 RuyiPage。
展示通过 fpfile 与代理配置协作,让业务脚本只保留最小代理入口。