Prompt
How do I integrate residential proxies into a scraping workflow?
Latest observation
Integrating residential proxies into a scraping workflow is mostly about using them as a network layer between your scraper and the target site, while keeping your scraper’s request patterns stable and respectful.
1) What residential proxies are used for
Residential proxies route traffic through IPs assigned to real consumer devices/networks. In scraping, they’re commonly used for:
- reducing IP-based blocking,
- accessing geo-restricted content,
- spreading requests across many IPs,
- testing localized experiences.
2) Basic workflow integration
A typical setup looks like:
-
Build your scraper
- Use
requests,httpx,aiohttp, Playwright, Selenium, Scrapy, etc.
- Use
-
Configure the proxy provider
- Get proxy credentials, endpoint, and protocol (
http,https, orsocks5). - Decide whether you need:
- rotating proxies (new IP per request or session),
- sticky sessions (same IP for a period).
- Get proxy credentials, endpoint, and protocol (
-
Route outbound requests through the proxy
- Add proxy settings at the client/session level.
-
Handle retries and rate limits
- Add backoff, timeouts, and request throttling.
-
Track success metrics
- Monitor status codes, CAPTCHA frequency, latency, and ban rates.
-
Rotate identity carefully
- Rotate IPs, user agents, cookies, and session state in a controlled way.
3) Example: Python requests
import requests
proxies = {
"http": "http://USER:PASS@proxy-host:port",
"https": "http://USER:PASS@proxy-host:port",
}
r = requests.get("https://example.com", proxies=proxies, timeout=30)
print(r.status_code)
print(r.text[:200])
If your provider uses a single gateway and handles rotation server-side, the endpoint may stay the same while the proxy network rotates IPs behind it.
4) Example: httpx
import httpx
proxies = "http://USER:PASS@proxy-host:port"
with httpx.Client(proxies=proxies, timeout=30) as client:
r = client.get("https://example.com")
print(r.status_code)
For async:
import httpx
import asyncio
async def main():
async with httpx.AsyncClient(proxies="http://USER:PASS@proxy-host:port", timeout=30) as client:
r = await client.get("https://example.com")
print(r.status_code)
asyncio.run(main())
5) Example: Scrapy
In settings.py:
DOWNLOADER_MIDDLEWARES = {
"scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware": 110,
}
HTTPPROXY_ENABLED = True
Then in your spider or middleware:
request.meta["proxy"] = "http://USER:PASS@proxy-host:port"
If you need rotation, implement a custom downloader middleware that assigns proxies per request.
6) Example: Playwright
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "http://proxy-host:port",
"username": "USER",
"password": "PASS",
}
)
page = browser.new_page()
page.goto("https://example.com")
print(page.title())
browser.close()
For browser scraping, proxies are often paired with:
- separate browser contexts,
- persistent cookies per session,
- realistic browser settings,
- consistent time zones/languages if needed.
7) Rotation strategy
Choose based on the target:
-
Per request rotation
- Good for large-scale collection where session continuity isn’t needed.
- Risk: more likely to trigger anti-bot systems if behavior looks unnatural.
-
Sticky session rotation
- Keep the same proxy IP for several minutes or a task.
- Better for logins, carts, forms, or multi-step flows.
-
Hybrid
- Use sticky sessions for a workflow, rotate between workflows.
8) Operational best practices
- Throttle requests
- Don’t fire requests too quickly from the same session.
- Use retries with exponential backoff
- Retry only on transient failures.
- Respect robots.txt and site terms
- Ensure your scraping is permitted.
- Cache results
- Avoid re-fetching identical pages.
- Separate concerns
- Keep proxy selection, HTTP client, parser, and storage modular.
- Monitor bans
- Track 403s, 429s, CAPTCHA pages, and soft blocks.
9) Common pitfalls
- Using one proxy for too many requests.
- Rotating IPs too aggressively during a login/session workflow.
- Forgetting to proxy both HTTP and HTTPS.
- Not handling DNS behavior correctly with the chosen proxy type.
- Ignoring headers, cookies, and browser fingerprinting.
10) Recommended architecture
A practical scraping pipeline often looks like:
- Scheduler / Queue
- Fetcher
- request library + proxy manager
- Proxy Manager
- rotates endpoints, tracks health
- Retry/Backoff Layer
- Parser
- Storage
- Monitoring
This makes it easier to swap providers or adjust rotation logic without changing your scrapers.
If you want, I can show you a full example in Python for:
requests,Scrapy, orPlaywright
with proxy rotation and retries.