> 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/integrations/cn/proxy-integrations/residential-proxies-guides/playwright.md).

# Playwright

[**Playwright**](https://playwright.dev/) 是一个 Node.js 库，可让您使用同一套 API 编写脚本并自动化浏览器，例如 Chrome、Firefox 和 Safari。它是一个便于自动化和测试的框架。&#x20;

要将 Playwright 与 Oxylabs 集成 [**住宅代理**](https://oxylabs.io/products/residential-proxy-pool)**,** 按照以下步骤操作，或观看此视频教程：

{% embed url="<https://youtu.be/KIsQ7ggB5DU>" %}

**步骤 1。** 安装 Node.js 和你选择的代码编辑器。（如果你已经安装，请跳过这一步）

**步骤 2。** 创建一个 Node.js 项目并安装所需的软件包。&#x20;

**步骤 3。** 在 Playwright 中，填写 `'proxy'` 值：

**服务器**: `'http://pr.oxylabs.io:7777'`

{% hint style="info" %}
你也可以使用随机或粘性国家/地区特定条目。例如，如果你输入 `http://us-pr.oxylabs.io:10000`下，你将获得一个美国出口节点。如果你输入 `10001` 在 **端口**，你将获得带有粘性会话的美国出口节点。你可以在 [**这里**](https://developers.oxylabs.io/proxies/residential-proxies/country-specific-entry-nodes#random-proxy-entry-nodes) 找到完整的国家/地区特定随机代理入口节点列表，以及粘性代理入口节点列表 - [**这里**](https://developers.oxylabs.io/proxies/residential-proxies/country-specific-entry-nodes#sticky-proxy-entry-nodes).
{% endhint %}

**用户名：** `'Oxylabs 代理用户用户名'`

**密码：** `'Oxylabs 代理用户密码'`

代码示例如下：

```
const playwright = require('playwright');
(async () => {
    for (const browserType of ['chromium', 'firefox', 'webkit']) {
        const browser = await playwright[browserType].launch({
            headless: false,
            proxy: {
                server: 'http://pr.oxylabs.io:7777',
                username: 'USERNAME',
                password: 'PASSWORD'
            },
        });
        const context = await browser.newContext();
        const page = await context.newPage();
        await page.goto('https://ip.oxylabs.io');
        await page.screenshot({ path: `${browserType}.png` });
        await browser.close();
    }
})();
```

就这样！你已经成功将 Oxylabs [**住宅代理**](https://oxylabs.io/products/residential-proxy-pool) 使用 Playwright。

如果您想了解更多关于使用 Playwright 进行网页抓取的信息，请阅读我们的 [**博客文章**](https://oxylabs.io/blog/playwright-web-scraping).

查找原始的 Playwright 集成博客文章 [这里](https://oxylabs.io/resources/integrations/playwright).


---

# 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:

```
GET https://developers.oxylabs.io/integrations/cn/proxy-integrations/residential-proxies-guides/playwright.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.
