All systems operational HTTP · HTTPS · SOCKS5 Global network
Documentation home Quickstart Engineering guides Code examples Global network Pricing Solutions overview Custom proxy pools Managed data scraping Contact Console
CODE EXAMPLE

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.

LanguagePython 3.11+FrameworkScrapyGatewayRotating ProxiesFilequotes_spider.py
01
SETUP

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.

Installpython -m pip install scrapy
02
CREDENTIALS

Load 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-secret
03
COMPLETE EXAMPLE

quotes_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)
04
WHAT THE EXAMPLE DOES

Keep the important behavior visible.

01Proxy URL is attached in request metadata.
02Per-domain concurrency is bounded.
03Pagination stays inside allowed domains.
04Structured items are yielded incrementally.
05
PRODUCTION NOTES

Add workload-specific controls before scale.

A successful sandbox run proves integration, not production readiness.

Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.

06
EXAMPLE FAQ

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.