Slashes and Brackets in Web Scraping with Python 2026: XPath vs CSS Explained Introduction to the Scrapy Selector in Python 2026 Setting up a Selector in Python 2026: Best Practices for Web Scraping Selecting Selectors in Python 2026: Best Practices for Web Scraping Extracting Data from a SelectorList in Python 2026: Best Practices CSS Locators in Python 2026: Powerful Web Scraping Techniques Attributes in CSS Selectors for Web Scraping in Python 2026 Selectors with CSS in Python 2026: Modern Web Scraping Techniques Text Extraction in Python 2026: Modern Techniques & Best Practices Crawl in Python 2026: Building Modern Web Crawlers with Best Practices A Classy Spider in Python 2026: Building Web Crawlers with Elegance & Best Practices Nodriver Canvas Fingerprint Spoofing 2026 – Advanced Anti-Detection Techniques WebGL Fingerprint Spoofing Techniques 2026 – Advanced Python Web Scrapping Evasion AudioContext Fingerprint Spoofing Techniques 2026 – Advanced Python Web Scrapping Evasion WebGL + AudioContext Integration Spoofing Techniques 2026 – Advanced Python Web Scrapping Evasion Canvas + WebGL Integration Spoofing Techniques 2026 – Advanced Python Web Scrapping Evasion Web Scraping with Python 2026 Web Scraping with Python in 2026 – Complete Beginner to Advanced Guide Python Web Scraping Tutorial 2026 – Playwright, Scrapy & BeautifulSoup Guide Building Your First Scrapy Spider in 2026 – Modern Python Web Scrapping Guide View all in this category →

Mastering Crawling & Pagination in Scrapy 2026 – Complete Python Web Scrapping Guide

Web Scraping Mar 19, 2026

Crawling is the heart of any serious web scrapping project. In Scrapy (still the #1 framework for structured crawling in 2026), crawling means systematically following links across pages, handling pagination, respecting depth limits, and extracting data at scale — all while avoiding blocks and staying ethical.

This updated 2026 guide explains how to build robust crawlers with Scrapy 2.14+, including modern async patterns, pagination strategies, CrawlSpider rules, depth control, and best practices to stay under the radar.

What Does "Crawling" Mean in Web Scrapping?

Crawling = discovering and visiting new pages by following hyperlinks. In Scrapy, this happens through:

  • start_urls + parse() → manual following
  • response.follow() → link following
  • CrawlSpider + Rule → automatic link extraction & pagination

Option 1: Manual Crawling with Basic Spider (Simple Pagination)


# spiders/news_crawler.py
import scrapy

class NewsCrawler(scrapy.Spider):
    name = "news"
    start_urls = ["https://example.com/news/page/1"]

    def parse(self, response):
        # Extract articles on current page
        for article in response.css("article.post"):
            yield {
                "title": article.css("h2::text").get(),
                "url": article.css("h2 a::attr(href)").get(),
                "date": article.css(".date::text").get()
            }

        # Follow next page (pagination)
        next_page = response.css("a.next::attr(href)").get()
        if next_page:
            yield response.follow(next_page, callback=self.parse)

Option 2: Automatic Crawling with CrawlSpider + Rules (Recommended 2026)

Use CrawlSpider for automatic link discovery and pagination handling.


# spiders/blog_spider.py
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class BlogSpider(CrawlSpider):
    name = "blog"
    allowed_domains = ["example.com"]
    start_urls = ["https://example.com/blog/"]

    rules = (
        # Extract all article links and parse them
        Rule(LinkExtractor(allow=r"/blog/article/"), callback="parse_article", follow=True),
        
        # Follow pagination links (common patterns)
        Rule(LinkExtractor(allow=r"/page/\d+/", deny=r"/page/1000/"), follow=True),
    )

    def parse_article(self, response):
        yield {
            "title": response.css("h1.article-title::text").get(),
            "content": response.css("div.content").get(),
            "author": response.css(".author::text").get(),
            "url": response.url
        }

Depth & Performance Control in 2026

Set these in settings.py to prevent infinite crawling:


DEPTH_LIMIT = 5              # max link depth
DEPTH_PRIORITY = 1           # higher depth = lower priority
CONCURRENT_REQUESTS = 8
DOWNLOAD_DELAY = 1.2         # polite delay
RANDOMIZE_DOWNLOAD_DELAY = True

How Pagination Crawling Stops

Pagination is the most common form of crawling: a list spread over pages 1, 2, 3 and so on. The spider reads one page, yields its items, then follows the next-page link. The crawl ends when there is no next link.

Relying only on the next link can go wrong if a site loops back to page 1 or shows an empty page with a next link. Add a second stop condition, such as no items found or a maximum page number, and let Scrapy's duplicate filter drop repeated URLs.

Keep DOWNLOAD_DELAY and ROBOTSTXT_OBEY switched on, since pagination can create many requests quickly.

Worked Example: Following Next Links With Two Stop Rules

We simulate a paginated listing in a dictionary and follow next links until a stop rule fires.

from bs4 import BeautifulSoup

PAGES = {
    "/page/1/": '<li>A</li><li>B</li><a class="next" href="/page/2/">Next</a>',
    "/page/2/": '<li>C</li><a class="next" href="/page/3/">Next</a>',
    "/page/3/": '<a class="next" href="/page/4/">Next</a>',
}

def crawl_pages(url="/page/1/", max_pages=50):
    items, visited = [], 0
    while url and visited < max_pages:
        soup = BeautifulSoup(PAGES.get(url, ""), "html.parser")
        visited += 1
        found = [li.get_text() for li in soup.select("li")]
        if not found:
            print("Stopped: empty page", url)
            break
        items += found
        nxt = soup.select_one("a.next")
        url = nxt["href"] if nxt else None
    return items

print(crawl_pages())

The crawler collects A, B and C. Page 3 has a next link but no items, so the empty-page rule stops the crawl there instead of requesting page 4.

Practical Tips

Log the page number and item count for each page. A page with far fewer items than usual often signals a layout change or a block, and the log helps you find it quickly.

Common Mistakes

  • Trusting the next link as the only stop condition.
  • Building page URLs by counting without checking the real last page.
  • Turning off the duplicate filter.
  • Crawling pagination without any delay.

Quick Summary

  • Follow next links page by page.
  • Stop on empty pages or a page limit.
  • Let the duplicate filter drop repeats.
  • Keep delays and robots rules on.

2026 Best Practices for Reliable Crawling

  • Use async def parse() when possible (Scrapy 2.13+)
  • Integrate scrapy-playwright for JavaScript-rendered pagination
  • Rotate User-Agents & headers via scrapy-user-agents middleware
  • Enable ROBOTSTXT_OBEY = True by default
  • Add realistic delays & concurrent request limits
  • Save output incrementally: scrapy crawl blog -o data.jl -s FEED_EXPORT_ENCODING=utf-8

Ethical & Legal Reminders for Crawling

Always respect robots.txt, avoid aggressive crawling, and prefer official APIs when available. High-volume crawling of protected sites can lead to IP bans or legal notices.

Last updated: March 19, 2026 – Scrapy 2.14 brings better coroutine support and improved link extractors, making crawling more efficient and reliable than ever.

Related Tutorials

Share:
Last updated: March 2026
Built-in Functions in Python 2026 str() in Python 2026: String Conversion + Modern Formatting & Best Practices memoryview with JAX in Python 2026: Zero-Copy NumPy → JAX Array Interop + Efficient ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + GPU Pinning & ML Examples memoryview with TensorFlow in Python 2026: Zero-Copy NumPy → Tensor Interop + ML Examples memoryview with NumPy & PyTorch in Python 2026: Zero-Copy Views, Efficient Slicing & ML Interop Examples memoryview with NumPy in Python 2026: Zero-Copy Views, Efficient Slicing & Real ML Examples memoryview() in Python 2026: Zero-Copy Magic for Large Binary Data + Real Examples import() in Python 2026: How It Works, Security Risks & Modern Alternatives (importlib) zip() in Python 2026: How to Use It, strict=True Behavior & Real-World Examples vars() in Python 2026: Accessing Object Namespace + Modern Introspection Patterns type() in Python 2026: Dynamic Type Inspection & Object Creation + Modern Patterns tuple() in Python 2026: Immutable Sequences + Modern Patterns & Best Practices super() in Python 2026: Method Resolution & Modern Inheritance Patterns sum() in Python 2026: Summing Iterables + Modern Numeric Patterns & Best Practices staticmethod() in Python 2026: Static Methods, Utility Functions & Modern Best Practices sorted() in Python 2026: Sorting Iterables + Modern Patterns & Best Practices slice() in Python 2026: Creating Slice Objects + Modern Patterns & Best Practices setattr() in Python 2026: Dynamic Attribute Setting + Modern Patterns & Safety set() in Python 2026: Mutable Sets Creation + Modern Patterns & Best Practices