> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/documentation/cn/kai-shi-shi-yong/quick-start-headless-browser.md).

# 快速开始：无头浏览器

通过简单的分步指南，几分钟内即可开始使用 Oxylabs 无头浏览器。

{% hint style="success" %}
已经熟悉基础内容？查看 [无头浏览器文档](/products/cn/headless-browser.md).
{% endhint %}

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 Secure 身份验证）。
   {% 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 = "hb.oxylabs.io"
browser_url = f"wss://{username}:{password}@{endpoint}"

with sync_playwright() as p:
    # 连接到远程 Oxylabs 浏览器
    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 %}

### 浏览器自定义

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

<table><thead><tr><th width="138.5">参数</th><th width="172">示例</th><th>描述</th></tr></thead><tbody><tr><td><code>p_cc</code></td><td><code>?p_cc=US</code></td><td>将浏览器流量路由通过特定国家。</td></tr><tr><td><code>p_device</code></td><td><code>?p_device=mobile</code></td><td>模拟特定设备类型。</td></tr><tr><td><code>session_name</code></td><td><code>?session_name=ses-1</code></td><td>创建粘性会话，使你的远程浏览器实例持续在云端运行。</td></tr></tbody></table>

在无头浏览器 [文档中](/products/cn/headless-browser.md#features).

### 下一步

* **想监控你的浏览器吗？** 了解 [Session Inspection Tool](/products/cn/headless-browser/session-inspection-and-recording.md) ，以实时可视化跟踪脚本与浏览器的交互。
* **你的脚本太慢吗？** 试试 [优化流量](/products/cn/headless-browser.md#recommended-setup) 以阻止不必要的资源加载。这将提高抓取速度并减少带宽消耗。
* **遇到错误或超时？** 访问 [故障排除指南](/products/cn/headless-browser/troubleshooting-guide.md) 以解决常见的 CDP 连接问题、库版本不匹配和执行超时。
* **在大型网站上遇到 "403 Forbidden"？** 查看 [受限目标](/products/cn/headless-browser/restricted-targets.md) 列表，了解哪些网站或服务限制通过无头浏览器访问。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/documentation/cn/kai-shi-shi-yong/quick-start-headless-browser.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
