PiratProxies

Web scraping

Proxies in Scrapy Playwright: working examples

scrapy-playwright lets Scrapy load pages in a real browser. The browser does not use Scrapy's proxy setting; it needs the proxy in its own launch options.

The right proxy type for Scrapy 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.

The values to enter in Scrapy 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.

Hostresi.piratproxies.com
HTTP port8080
SOCKS5 port1080
UsernameUSERNAME
Passwordshown 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 Scrapy Playwright

  1. Set the proxy in PLAYWRIGHT_LAUNCH_OPTIONS, with the username and password as separate keys.
  2. For a different IP address per page group, create browser contexts with their own proxy through playwright_context_kwargs.

Code: Scrapy Playwright through a proxy

settings.py

PLAYWRIGHT_LAUNCH_OPTIONS = {
    "proxy": {
        "server": "http://resi.piratproxies.com:8080",
        "username": "USERNAME",
        "password": "PASSWORD",
    },
}

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 Scrapy Playwright rotate IPs or keep one?

When Scrapy 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-a1b2c3d4

When Scrapy Playwright will not connect

  • meta["proxy"] is ignored for requests that go through the browser. Only the launch or context options count.
  • A browser loads images, fonts and scripts. Block what you do not need, or a gigabyte plan drains much faster than with plain requests.
  • Error 407 means 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.

Scrapy Playwright and proxies: questions

Can Scrapy Playwright use a SOCKS5 proxy?

Only without a login: Scrapy 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 Scrapy 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.

Scrapy 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.