# 快速入门：无头浏览器

Oxylabs [无头浏览器](https://oxylabs.io/products/headless-browser) 是一个托管在云端的浏览器基础设施，可自动处理反机器人系统、CAPTCHA 和代理轮换。它与 Playwright、Puppeteer 以及面向 AI 应用的 Model Context Protocol (MCP) 完全兼容。

{% stepper %}
{% step %}

### 设置与凭据

1. **创建账户：** 在以下位置注册： [Oxylabs Dashboard](https://dashboard.oxylabs.io/).
2. **选择方案：** 在 Scraping Solutions → 无头浏览器 下选择方案或免费试用。
3. **创建用户凭据：** 前往无头浏览器产品部分中的 Users 选项卡，创建用户名和密码（这些凭据用于 WebSocket 身份验证）。
   {% endstep %}

{% step %}

### 你的第一个请求

Oxylabs 无头浏览器使用 Chrome DevTools Protocol (CDP)。你可以使用 Playwright 或 Puppeteer 连接它，无需管理本地浏览器二进制文件。

**Python + Playwright 示例：**

1. 安装 Playwright： `pip install playwright`
2. 运行以下脚本（替换 `USERNAME` 和 `PASSWORD` 为你的凭据）：

```python
from playwright.sync_api import sync_playwright

username = "USERNAME"
password = "PASSWORD"
endpoint = "ubc.oxylabs.io"
browser_url = f"wss://{username}:{password}@{endpoint}"

with sync_playwright() as p:
    # Connect to the remote Oxylabs browser
    browser = p.chromium.connect_over_cdp(browser_url)
    page = browser.new_page()
    
    page.goto('https://oxylabs.io/')
    print(f"Page Title: {page.title()}")
    
    browser.close()
```

{% endstep %}
{% endstepper %}

### 连接参考

使用与你偏好的浏览器和地理位置最接近的端点：

| 浏览器     | 全球端点                   | 美国端点                      |
| ------- | ---------------------- | ------------------------- |
| Chrome  | `wss://ubc.oxylabs.io` | `wss://ubc-us.oxylabs.io` |
| Firefox | `wss://ubs.oxylabs.io` | `wss://ubs-us.oxylabs.io` |

### 自定义浏览器

你也可以通过连接 URL，使用查询参数直接传递指令：

| 参数         | 示例                 | 描述                                  |
| ---------- | ------------------ | ----------------------------------- |
| `p_cc`     | `?p_cc=US`         | 将浏览器流量路由到特定国家。                      |
| `p_device` | `?p_device=mobile` | 模拟特定设备类型（仅 Chrome）。                 |
| `o_vnc`    | `?o_vnc=true`      | 启用 Session Inspection Tool 进行可视化调试。 |

### 下一步

* **想监控你的浏览器？** 了解 [Session Inspection Tool](/products/headless-browser/features/session-inspection.md) 以实时可视化跟踪脚本与浏览器的交互。
* **你的脚本太慢了吗？** 尝试 [Optimizing Traffic](/products/headless-browser/optimizing-traffic.md) 以阻止不必要的资源加载。这会提升抓取速度并减少带宽消耗。
* **遇到错误或超时？** 访问 [Troubleshooting Guide](/products/headless-browser/troubleshooting-guide.md) 以解决常见的 CDP 连接问题、库版本不匹配和执行超时。
* **在大型网站上遇到“403 Forbidden”吗？** 查看 [Restricted Targets](/products/headless-browser/restricted-targets.md) 列表，了解哪些网站或服务对无头浏览器的访问受到限制。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.oxylabs.io/documentation/cn/kai-shi-shi-yong/kuai-su-ru-men-wu-tou-liu-lan-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
