Route Scrapy crawls through one rotating gateway.
Route Scrapy crawls through one rotating gateway. This example uses Rotating Proxies as the default gateway and can be adapted by replacing endpoint and routing credentials.
Install the client and create a file.
Use a clean project environment and pin tested dependency versions for production. The example target is a public scraping sandbox.
python -m pip install scrapyLoad proxy secrets from the environment.
The proxy username is not the LundProxy website login. Copy the complete username and password generated for the selected proxy product.
PROXY_USER=user-pool-crawlerPROXY_PASS=your-secretquotes_spider.py
Copy the code into the named file, set credentials, and run it from the project environment.
import os
from urllib.parse import quote
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
allowed_domains = ["quotes.toscrape.com"]
start_urls = ["https://quotes.toscrape.com/"]
custom_settings = {
"DOWNLOAD_TIMEOUT": 30,
"RETRY_TIMES": 3,
"CONCURRENT_REQUESTS_PER_DOMAIN": 4,
}
def start_requests(self):
user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASS"], safe="")
proxy = f"http://{user}:{password}@proxy.lundproxy.com:36923"
yield scrapy.Request(self.start_urls[0], meta={"proxy": proxy})
def parse(self, response):
for quote_node in response.css(".quote"):
yield {
"text": quote_node.css(".text::text").get(),
"author": quote_node.css(".author::text").get(),
}
next_page = response.css("li.next a::attr(href)").get()
if next_page:
yield response.follow(next_page, callback=self.parse)
Keep the important behavior visible.
Add workload-specific controls before scale.
Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.
Scrapy questions.
Will followed requests keep the proxy?
Scrapy copies request metadata for common follow flows, but explicit middleware is safer for complex projects.
Where should I rotate SESSION?
Generate it in downloader middleware or job metadata, not inside the parser.
How should 429 be handled?
Reduce per-domain concurrency and use bounded delayed retries.