将Playwright代理与Bright Data集成

Learn how to setup your Playwright proxy settings and integrate with Bright Data's Proxy IPs

Playwright是一个Node.js库,可通过单个API自动化Chromium、Firefox和 WebKit。本页会介绍Playwright与 Bright Data集成所需的所有步骤。立刻使用旋转代理来强化您的Playwright代理,摆脱网页屏蔽。

将Bright Data超级代理与Playwright集成

  • 首先进入Bright Data 仪表板并点击“创建通道”。
  • 选择“网络类型”并点击保存。
  • 在Playwright中,将’Proxy IP:Port’填入“服务器”值中,例如 http://zproxy.lum-superproxy.io:22225.
  • 在“用户名”下输入Bright Data帐户ID和代理通道名称,例如::lum-customer-CUSTOMER-zone-YOURZONE ,在“密码”下输入通道设置中的通道密码。
  • 例如:
const playwright = require('playwright');

(async () => {
    for (const browserType of ['chromium', 'firefox', 'webkit']) {
        const browser = await playwright[browserType].launch({
            headless: false,
            proxy: {
                server: 'http://zproxy.lum-superproxy.io:22225',
                username: 'lum-customer-USERNAME-zone-YOURZONE',
                password: 'PASSWORD'
            },
        });
        const context = await browser.newContext();
        const page = await context.newPage();
        await page.goto('http://lumtest.com/myip.json');
        await page.screenshot({ path: 'example.png' });
        await browser.close();
    }
})();

将代理管理器与Playwright集成

  • 创建包含想要使用的网络、IP类型和IP数量的通道。
  • 安装代理管理器。
  • 点击“新建代理”并选择需要的通道和设置,点击“保存”。
  • 在Playwright中,在“服务器”下,输入本地IP和代理管理器端口(即 127.0.0.1:24000)。
    • 本机主机IP为127.0.0.1
    • 代理管理器中创建的端口是24XXX。例如,24000
  • 因为 Bright Data代理管理器已经通过超级代理验证,所以用户名和密码值可留空。
  • 例如:
const playwright = require('playwright');

(async () => {
    for (const browserType of ['chromium', 'firefox', 'webkit']) {
        const browser = await playwright[browserType].launch({
            headless: false,
            proxy: {
                server: '127.0.0.1:24000',
                username: '',
                password: ''
            },
        });
        const context = await browser.newContext();
        const page = await context.newPage();
        await page.goto('http://lumtest.com/myip.json');
        await page.screenshot({ path: 'example.png' });
        await browser.close();
    }
})();

Dataset Sample Request

电话咨询