# Playwright

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

要将 Playwright 与 Oxylabs 集成 [**移动代理**](broken://pages/7c50b210d807de54753cf5eb3a868b41c8c528dd)**,** 请按照以下步骤操作：

**步骤 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 移动代理集成 到 Playwright 中。

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

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


---

# 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/integrations/cn/proxy-integrations/mobile-proxies-guides/playwright-1.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.
