Using our proxies with Scrapy
Scrapy's built-in HttpProxyMiddleware reads the proxy from each request's meta, so you can set it per request or for the whole spider. Use it only for sources whose terms allow automated access.
Pick a proxyCompatibility
- HttpProxyMiddleware sets the proxy from request.meta['proxy']; this value takes precedence over http_proxy / https_proxy and ignores no_proxy.
- Credentials can be written in the proxy URL: http://username:password@host:port.
- http:// and https:// proxy URLs both work for HTTP and HTTPS targets.
- SOCKS5 works only with a download handler that supports it; among the built-in ones that is HttpxDownloadHandler (added in Scrapy 2.15, marked experimental).
- Protocols:
- HTTP, HTTPS (CONNECT), SOCKS5
- Connection:
- Username and password, IP allowlist
Configuration
# ipcheck.py — HttpProxyMiddleware is enabled by default
import scrapy
class IpCheckSpider(scrapy.Spider):
name = "ipcheck"
def start_requests(self):
yield scrapy.Request(
"https://api.ipify.org?format=json",
meta={"proxy": "http://USERNAME:PASSWORD@PROXY_HOST:PORT"},
)
def parse(self, response):
self.logger.info("Exit IP: %s", response.json()["ip"])The spider sends one request with the proxy in meta and logs the exit IP from the JSON response. In a real project, set the same meta key in start requests or in a small downloader middleware. For IP allowlist access, remove USERNAME:PASSWORD@.
PROXY_HOST, PORT, USERNAME and PASSWORD are placeholders. After we select proxies for your task, we send you the real host, port and credentials.
Check the result
scrapy runspider ipcheck.py
# look for: Exit IP: <exit IP>- Run scrapy runspider ipcheck.py and find the "Exit IP" line in the log; it must match the IP we sent you.
- Look up the exit IP in two independent GeoIP services and confirm both show the country (and city, if you asked for one) from your request. GeoIP databases can disagree; tell us if they do.
- Crawl one permitted page and inspect the response: status code, language and currency should match the requested country.
What to put in the request
- Scrapy version and download handler (default or HttpxDownloadHandler if you need SOCKS5).
- Sources you plan to collect from and confirmation that their terms permit it.
- Country, session mode (static, sticky, rotating) and CONCURRENT_REQUESTS you plan to run.
- Access method: username/password or IP allowlist.
Common pitfalls
- Setting the proxy on a request handled by H2DownloadHandler: per the Scrapy docs it does not support the proxy meta key.
- Expecting a socks5:// proxy URL to work with the default handler; only handlers that support SOCKS accept it.
- Ignoring robots.txt and site terms. Keep ROBOTSTXT_OBEY enabled and crawl only sources you are allowed to use.
Recommended proxy types
Sources
Not sure which proxy fits?
Describe the task in two sentences. We reply with a concrete setup and price, usually within one business day.
Availability, exact parameters and price are confirmed in our reply after manual selection. Nothing is charged automatically.