Data & Research31 Aug 20265 min read

How to Use Proxies with Playwright, Selenium & Python Requests: Quick Setup Guide

A simple, step-by-step developer guide on configuring rotating and authenticated proxies in Playwright, Selenium, and Python Requests with clean, copy-paste code examples.

Jade Carter
Jade CarterSenior Network Infrastructure Engineer
How to Use Proxies with Playwright, Selenium & Python Requests: Quick Setup Guide
Key Engineering Takeaways
  • Quick setup patterns for connecting authenticated residential and datacenter proxies to Python Requests, Playwright, and Selenium.
  • Dual-protocol endpoints support standard HTTP (port 8080) and SOCKS5 (port 1080) configurations.
  • Username targeting parameters allow easy configuration of country-specific IP rotation or sticky sessions.
  • Ready-to-use, minimal code examples for fast testing and integration into your scripts.

How to Connect Proxies with Playwright, Selenium & Python Requests

Setting up proxies in your automation scripts is straightforward. Whether you need a fresh rotating IP for every web request or a sticky IP that holds the same session, this guide shows you the exact code required for three popular tools: Python Requests, Playwright, and Selenium.

1. Proxy Credentials & Endpoint Syntax

ITN PROXY provides single-gateway endpoints that handle rotation and geo-targeting directly through your authentication string:

  • HTTP Host: resi.itnproxy.com
  • HTTP Port: 8080
  • SOCKS5 Port: 1080

Username Parameters:

  • Rotating (Default): customer_id (gives a fresh IP on every connection)
  • Country Targeting: customer_id-country-us (routes through the selected country)
  • Sticky Session: customer_id-session-mysession123-sessTime-30 (holds the same IP for up to 30 minutes)

2. Python Requests Setup

Requests is the most widely used HTTP library in Python. You can pass your proxy URL directly into the proxies dictionary.

python
import requests

# 1. Define proxy host, port, and credentials
PROXY_HOST = "resi.itnproxy.com"
PROXY_PORT = "8080"
USERNAME = "customer_id-country-us"
PASSWORD = "password_secret"

# 2. Build the proxy URL dictionary
proxies = {
    "http": f"http://{USERNAME}:{PASSWORD}@{PROXY_HOST}:{PROXY_PORT}",
    "https": f"http://{USERNAME}:{PASSWORD}@{PROXY_HOST}:{PROXY_PORT}",
}

# 3. Send a test request
try:
    response = requests.get("https://ipinfo.io/json", proxies=proxies, timeout=15)
    print("Response Status:", response.status_code)
    print("Current Proxy IP:", response.json())
except requests.exceptions.RequestException as e:
    print("Connection error:", e)

3. Playwright Setup

Playwright has native, built-in proxy support with automatic authentication at both the browser launch and context levels.

A. Python (Playwright Sync)

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    
    # Configure proxy credentials in the browser context
    context = browser.new_context(
        proxy={
            "server": "http://resi.itnproxy.com:8080",
            "username": "customer_id-country-us",
            "password": "password_secret",
        }
    )
    
    page = context.new_page()
    page.goto("https://ipinfo.io/json")
    print("Playwright Output:", page.inner_text("body"))
    
    browser.close()

B. JavaScript / Node.js (Playwright)

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

(async () => {
  const browser = await chromium.launch({ headless: true });
  
  // Set up proxy configuration
  const context = await browser.newContext({
    proxy: {
      server: 'http://resi.itnproxy.com:8080',
      username: 'customer_id-country-us',
      password: 'password_secret',
    },
  });

  const page = await context.newPage();
  await page.goto('https://ipinfo.io/json');
  
  const bodyText = await page.textContent('body');
  console.log('Playwright IP Data:', bodyText);

  await browser.close();
})();

4. Selenium Setup (Python)

In standard Selenium, pass the proxy server directly using the --proxy-server argument in ChromeOptions.

Installation:

bash
pip install selenium webdriver-manager

Example Code:

python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

# 1. Configure standard Chrome options with proxy server
options = Options()
options.add_argument("--proxy-server=http://resi.itnproxy.com:8080")
options.add_argument("--headless=new")

# 2. Launch standard Selenium Chrome Driver
driver = webdriver.Chrome(
    service=Service(ChromeDriverManager().install()),
    options=options
)

try:
    driver.get("https://ipinfo.io/json")
    print("Selenium Output:", driver.find_element("tag name", "body").text)
finally:
    driver.quit()

5. Summary

  • Python Requests: Lightweight and fast for HTTP requests, API calls, and data pipelines without browser rendering.
  • Playwright: Modern browser automation with built-in proxy username and password authentication support.
  • Selenium: Standard browser automation configured directly via --proxy-server Chrome options.
Tags:#Playwright#Selenium#Python Requests#Proxy Setup
Jade Carter
About the Author

Jade Carter

Senior Network Infrastructure Engineer

Specializing in distributed network architectures, high-throughput edge routing, cloud infrastructure, and large-scale data systems.

Start in 60 Seconds

Test ITN PROXY with 50 MB Free Residential Proxies

Instant access to 100M+ real peer residential IPs across 190+ countries with city/ASN targeting and unlimited concurrency.

Related Articles & Guides

Continue exploring proxies, anti-bot strategies, and web scraping architectures.