PlaywrightプロキシとBright Dataの統合

Playwrightプロキシ設定をセットアップし、Bright DataのプロキシIPと統合する方法について

PlaywrightはChromium・Firefox・WebKitを単一APIで自動化するNode.jsライブラリです。Playwrightを確実にBright Dataと統合するために必要なすべての手順が用意されます。

Bright DataのスーパープロキシとPlaywrightの統合

  • まずBright Dataのダッシュボードにアクセスし、「ゾーンの作成」をクリックします。
  • 「ネットワークタイプ」を選択し、保存をクリックします。
  • Playwrightの「サーバー」値の「プロキシIP:ポート」に値を入力します。たとえば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の数でZone を作成します。
  • プロキシマネージャをインストールします。
  • 「新しいプロキシの追加」をクリックして必要なZone と設定を選択し、「保存」をクリックします。
  • 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();
    }
})();