# 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).
