The right proxy type for Playwright
For most scraping, Residential Lite is the cheapest way to get home IP addresses in the right country. Use Residential when you need a particular state or city, and Unlimited Datacenter for targets in the United States that do not block data centre addresses.
- Residentialfrom $2.64 per GB
- Residential Litefrom $0.60 per GB
- Unlimited Datacenterfrom $0.56 per hour
The values to enter in Playwright
Every PiratProxies plan comes down to four values: host, port, username and password. Here they are for Residential; your own username and password are on your plan page.
| Host | resi.piratproxies.com |
|---|---|
| HTTP port | 8080 |
| SOCKS5 port | 1080 |
| Username | USERNAME |
| Password | shown on your plan page |
There is no separate country or session field: both are part of the username. Your plan page has a generator that writes it, and Targeting and sessions describes each piece.
Setting it up in Playwright
- Give
server,usernameandpasswordas separate values when launching the browser. - For several IP addresses in one browser, set a different
proxyon each browser context.
Code: Playwright through a proxy
Python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={"server": "http://resi.piratproxies.com:8080", "username": "USERNAME", "password": "PASSWORD"})
page = browser.new_page()
page.goto("https://api.ipify.org")
print(page.inner_text("body"))
browser.close()Node.js
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ proxy: { server: 'http://resi.piratproxies.com:8080', username: 'USERNAME', password: 'PASSWORD' } });
const page = await browser.newPage();
await page.goto('https://api.ipify.org');
console.log(await page.innerText('body'));
await browser.close();
})();Put your own login from the plan page in place of USERNAME and PASSWORD. The example calls an IP-check service, so what it prints is the address your request came from.
Should Playwright rotate IPs or keep one?
When Playwright is fetching lots of unrelated pages, leave the session out of the username and each request gets a fresh IP address. When requests belong together, such as a login, a basket or paginated results that set cookies, put a session in the username so they all share one address.
Here is what a sticky username looks like:
USERNAME-country-us-time-600-session-a1b2c3d4When Playwright will not connect
- A login written inside the
serveraddress is ignored. Use the separateusernameandpasswordkeys. - Each context with its own session ID in the username gets its own IP address, which is the cheap way to run many identities in one browser.
- Error
407means the login was refused. Copy the username and password from your plan page once more, and make sure no space crept in and the username was not cut short. - An IP in the wrong country nearly always comes from the username, since the country code lives there. Other fixes.
Playwright and proxies: questions
Can Playwright use a SOCKS5 proxy?
Only without a login: Playwright cannot send a SOCKS5 username and password. Use the HTTP port, 8080, instead; it handles http and https sites alike.
Which PiratProxies plan suits Playwright best?
For most scraping, Residential Lite is the cheapest way to get home IP addresses in the right country. Use Residential when you need a particular state or city, and Unlimited Datacenter for targets in the United States that do not block data centre addresses.
Words used in this guide: web scraping, rotating proxy, sticky session, rate limiting, headless browser.
Playwright belongs to its own developers, and PiratProxies has no connection with them; we name it only to say what this guide covers. Follow the rules of the sites you visit and our acceptable use policy.