Setup Guides · 1 min read
Scrapy Proxy Configuration: Middleware Setup Guide
How to configure proxies in Scrapy using middleware for web scraping projects.
NobleProxy Team · Updated
Scrapy Proxy Setup
Configure proxies in Scrapy for efficient web scraping.
TL;DR: Create custom middleware or use scrapy-rotating-proxies. Set proxy in request.meta for per-request control.
Basic Configuration
settings.py
# Single proxy
HTTP_PROXY = 'http://user:pass@proxy.nobleproxy.com:8080'
DOWNLOADER_MIDDLEWARES = {
'myproject.middlewares.ProxyMiddleware': 350,
}
middlewares.py
class ProxyMiddleware:
def process_request(self, request, spider):
request.meta['proxy'] = 'http://user:pass@proxy:port'
Rotating Proxies
Using scrapy-rotating-proxies
pip install scrapy-rotating-proxies
# settings.py
ROTATING_PROXY_LIST = [
'http://proxy1:port',
'http://proxy2:port',
'http://proxy3:port',
]
DOWNLOADER_MIDDLEWARES = {
'rotating_proxies.middlewares.RotatingProxyMiddleware': 610,
'rotating_proxies.middlewares.BanDetectionMiddleware': 620,
}
Per-Spider Proxy
class MySpider(scrapy.Spider):
def start_requests(self):
for url in self.start_urls:
yield scrapy.Request(
url,
meta={'proxy': 'http://proxy:port'}
)
Best Practices
- Implement retry logic
- Detect bans and rotate
- Use appropriate delays
- Log proxy performance
ProductStatic residentialOne dedicated proxy per account on a real home connection, with the same IP for the full term.Details ProductRotating residentialA new home IP on every request or sticky sessions up to 24 hours, in 116 countries.Details
#Scrapy #Python #web-scraping