Реферальна програма
Розробка

Налаштування проксі у Playwright

Скрапте сторінки з JavaScript-рендерингом через ротаційні проксі з Playwright.

Playwright автоматизує браузери Chromium, Firefox і WebKit - незамінний для скрапінгу сайтів, які рендерять контент через JavaScript. Налаштуйте SotaProxy на рівні запуску браузера, і кожна відкрита браузером сторінка йтиме через проксі.

Посібник із налаштування

1

Node.js - проксі на рівні браузера

javascript
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    proxy: {
      server: 'http://proxy.sotaproxy.com:10000',
      username: 'YOUR_USERNAME',
      password: 'YOUR_PASSWORD',
    },
  });

  const page = await browser.newPage();
  await page.goto('https://httpbin.org/ip');
  const content = await page.content();
  console.log(content);
  await browser.close();
})();

Задайте проксі в chromium.launch(). Усі сторінки, створені цим екземпляром браузера, йдуть через SotaProxy.

2

Python - проксі на рівні браузера

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://proxy.sotaproxy.com:10000",
            "username": "YOUR_USERNAME",
            "password": "YOUR_PASSWORD",
        }
    )
    page = browser.new_page()
    page.goto("https://httpbin.org/ip")
    print(page.content())
    browser.close()

Та сама конфігурація проксі в Python. Працює із sync_playwright і async_playwright.

3

Проксі на контекст (різні проксі на вкладку)

javascript
const browser = await chromium.launch();

// Each context gets its own proxy
const context1 = await browser.newContext({
  proxy: {
    server: 'http://proxy.sotaproxy.com:10000',
    username: 'YOUR_USERNAME_c_US',
    password: 'YOUR_PASSWORD',
  },
});

const context2 = await browser.newContext({
  proxy: {
    server: 'http://proxy.sotaproxy.com:10000',
    username: 'YOUR_USERNAME_c_DE',
    password: 'YOUR_PASSWORD',
  },
});

Запустіть один браузер, але створіть кілька контекстів із різними конфігураціями проксі. Кожен контекст ізольований - зручно для мультирегіонального тестування.

Автоматизуй через SotaProxy API

Усе описане вище працює без відкриття дашборда. З API-ключем Playwright може отримувати свіжі дані проксі, купувати нові та продовжувати ті, що спливають, - прямо з коду.

javascript
const API = 'https://api.sotaproxy.com/api/v1'
const H = { Authorization: 'Bearer sk_live_your_key' }

// Every active proxy on your account - no copy-pasting credentials
const { proxies } = await (await fetch(`${API}/proxies`, { headers: H })).json()
const p = proxies[0]
const proxyUrl = `http://${p.login}:${p.password}@${p.ip}:${p.portHttp}`

// Buy more when you scale (price-check first with POST /quote)
await fetch(`${API}/orders`, {
  method: 'POST',
  headers: { ...H, 'Content-Type': 'application/json', 'Idempotency-Key': 'my-unique-order-id' },
  body: JSON.stringify({ product: 'ipv4', countryId: 565, periodId: '1m', quantity: 5 }),
})
Документація API

Proxy at the browser or at the context

Playwright accepts credentials as separate fields rather than inside the URL. Context-level proxies are the feature that matters: every context can hold a different address in one browser process:

Rotating residential
login:password@proxy.sotaproxy.com:10000
Pinned to a country
login_c_US:password@proxy.sotaproxy.com:10000
Sticky for 15 minutes
login_c_US_s_42_ttl_15m:password@proxy.sotaproxy.com:10000
Static address (ISP, datacenter)
login:password@your-ip:50100, SOCKS5 on 50101

Pass server without credentials and put username and password in their own fields. Credentials inside the server URL are ignored by Chromium.

A different address per browser context

One browser, many contexts, each with its own address and its own cookie jar. That is the cheapest way to run parallel identities:

Python: one context per identity

from playwright.sync_api import sync_playwright

BASE = "http://proxy.sotaproxy.com:10000"

with sync_playwright() as p:
    browser = p.chromium.launch()
    for i in range(1, 6):
        ctx = browser.new_context(
            proxy={
                "server": BASE,
                "username": f"login_c_US_s_{i}_ttl_1h",
                "password": "password",
            },
            locale="en-US",
            timezone_id="America/New_York",
        )
        page = ctx.new_page()
        page.goto("https://example.com", timeout=30000)
  • Match locale and timezone to the proxy country. A US address with a Warsaw timezone is a contradiction that fingerprinting scripts read instantly.
  • Sticky sessions matter here. A rotation mid-page leaves half the assets loaded from another address.
  • Block images and media through routing when you only need markup. It cuts residential traffic several times over.
  • Set navigation timeouts to 30 seconds. The default 30000 milliseconds is right for us, shorter values throw away working routes.

Playwright specifics

Credentials inside server are ignored

Chromium strips them. If you see 407 in the network log, this is almost always why.

Localhost bypasses the proxy

Chromium never proxies loopback. Testing against a local mock server tells you nothing about the proxy path.

One context, many identities

Cookies and storage are per context. Reusing a context with a new address hands the site the previous identity on a new IP.

WebRTC still leaks the real address

The proxy does not cover it. Disable WebRTC in the context or the page reports your origin IP to any script that asks.

Нотатки та поради

  • Використовуйте headless: false під час розробки, щоб спостерігати за браузером і налагоджувати. Перемикайтеся на headless: true у продакшені.
  • Playwright автоматично обробляє HTTPS-проксі через CONNECT-тунелювання - додаткове налаштування не потрібне.
  • Для липких сесій увімкніть ID сесії в параметр імені користувача, щоб утримувати один IP між переходами сторінками.

FAQ

Чи можна використовувати Playwright із SOCKS5-проксі?

Так. Змініть URL сервера на socks5://proxy.sotaproxy.com:PORT. Уточніть SOCKS5-ендпоінт у дашборді SotaProxy.

Чи працює Playwright для скрапінгу сайтів під захистом Cloudflare?

Playwright із резидентними проксі справляється з більшістю сайтів під Cloudflare. Для складних цілей Cloudflare комбінуйте зі stealth-плагіном (playwright-extra + puppeteer-extra-plugin-stealth).

Отримай облікові дані проксі

Зареєструйся, поповни баланс і скопіюй ендпоінт у Playwright. Займе менше 5 хвилин.

Почати