Python

If you're scraping websites, automating browsers, or collecting public data, integrating proxies correctly is critical to avoid blocks and stay anonymous. This tutorial walks you through using Squid Proxies datacenter and residential proxies with Python — using both the requests library and Selenium for browser automation.

This guide is beginner-friendly and includes rotation logic for handling large-scale scraping tasks with fallback and retry support.


Proxy Format Overview

Proxy TypeFormat ExampleAuthentication
Datacenter123.45.67.89:3128IP Authorization Only
Residentialp102.squidproxies.com:8907IP Whitelisting & Username/Password Authorization

📌 Important: No username or password is required. Simply log in to your Squid Proxies dashboard and authorize your current IP address.


Setup Requirements & Prerequisites

1. Python

Version: Python 3.7 or later

python --version

2. Required Python Packages

Install using pip:

pip install requests selenium undetected-chromedriver

✔️ undetected-chromedriver is optional and useful for stealth scraping.

3. ChromeDriver for Selenium

  • Download the correct ChromeDriver for your browser
  • Add it to your system PATH or reference it directly in your script

4. Squid Proxies Setup

  • Have an active Squid Proxies account
  • Add your IP to the Authorized IPs list in the dashboard
  • Wait 1–3 minutes for it to activate

Using Squid Proxies with Python Requests

The requests library is ideal for simple HTTP GET/POST scraping.

Datacenter Proxy Example

import requests

proxy = {
    'http': 'http://123.45.67.89:3128',
    'https': 'http://123.45.67.89:3128',
}

url = 'https://httpbin.org/ip'

response = requests.get(url, proxies=proxy, timeout=10)
print("Public IP via Datacenter Proxy:", response.json())

Residential Proxy Example

import requests

proxy = {
    'http': 'http://p102.squidproxies.com:8907',
    'https': 'http://p102.squidproxies.com:8907',
}

url = 'https://httpbin.org/ip'

response = requests.get(url, proxies=proxy, timeout=10)
print("Public IP via Residential Proxy:", response.json())

☑️ Squid Proxies’ residential proxies rotate automatically approximately every 10 minutes.

Optional: Add Headers

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
    'Accept-Language': 'en-US,en;q=0.9',
}

response = requests.get(url, headers=headers, proxies=proxy, timeout=10)

Datacenter Proxy Rotation with Retry and Delay

To simulate rotation using multiple datacenter IPs:

import requests
import random
import time

proxy_list = [
    '123.45.67.1:3128',
    '123.45.67.2:3128',
    '123.45.67.3:3128',
]

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
    'Accept-Language': 'en-US,en;q=0.9'
}

def fetch_with_retry(url, max_retries=3, delay=3):
    for proxy_ip in proxy_list:
        proxy = {
            'http': f'http://{proxy_ip}',
            'https': f'http://{proxy_ip}',
        }

        for attempt in range(1, max_retries + 1):
            try:
                print(f"Trying proxy {proxy_ip} (attempt {attempt})")
                response = requests.get(url, proxies=proxy, headers=headers, timeout=10)
                if response.status_code == 200:
                    print("Success:", response.json())
                    return response.json()
                else:
                    print(f"Non-200 response: {response.status_code}")
            except requests.RequestException as e:
                print(f"Request failed with proxy {proxy_ip}: {e}")
                time.sleep(delay)

        print(f"Proxy {proxy_ip} failed after {max_retries} attempts. Trying next...")
        time.sleep(delay)

    print("All proxies failed.")
    return None

fetch_with_retry('https://httpbin.org/ip')

Integrating Squid Proxies with Selenium

Selenium automates browsers (like Chrome) for dynamic content and JavaScript-heavy pages.

Datacenter Proxy (Selenium Chrome)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--proxy-server=http://123.45.67.89:3128')

driver = webdriver.Chrome(options=options)
driver.get('https://httpbin.org/ip')

print(driver.page_source)
driver.quit()

Residential Proxy (Selenium Chrome)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--proxy-server=http://p102.squidproxies.com:8907')

driver = webdriver.Chrome(options=options)
driver.get('https://httpbin.org/ip')

print(driver.page_source)
driver.quit()

✅ Your residential IP will rotate automatically about every 10 minutes while using the same endpoint.


Beginner Tips for Python Proxy Usage

  • Always test your IP via https://httpbin.org/ip
  • Residential proxies are ideal for login sessions, geo-targeted scraping, and social automation
  • Datacenter proxies are faster and better for volume-based scraping
  • Add delays, headers, and retries to reduce bans
  • Never hard-code a single proxy for large jobs — rotate or randomize



More Guides: