Use ProxyHQ with Scrapy
Send Scrapy requests through ProxyHQ.
Connection details
Use these values. Your login and password are in your dashboard.
| Type | HTTP (or SOCKS5) |
| Host | gw.proxyhq.net |
| Port (HTTP / HTTPS) | 823 |
| Port (SOCKS5) | 824 |
| Sticky ports | 10000 - 20000 |
| Username | YOUR_LOGIN |
| Password | YOUR_PASSWORD |
Steps
- Scrapy's built-in proxy support reads the proxy from a request. Set it with the proxy key in meta.
- Put your login and password in the proxy URL. Scrapy turns them into the right header for you.
- Run the spider and check the IP in the response.
import scrapy PROXY = "http://YOUR_LOGIN__cr.us:[email protected]:823" class IpSpider(scrapy.Spider): name = "ip" def start_requests(self): yield scrapy.Request("https://api.ipify.org", meta={"proxy": PROXY}) def parse(self, response): self.logger.info("IP: %s", response.text)
To use the same proxy for every request, set it in a small downloader middleware or when you create each Request.
For several countries, create one URL per country by changing the __cr. code in the login.
Choose a country or a sticky IP
Add __cr.de (or another country code) to the end of your login to choose a country. Use a port from 10000 to 20000 for a sticky IP. See country targeting and rotating vs sticky.
Stuck? See troubleshooting or email [email protected].