# Web Scraping With Scrapy and MongoDB

DevFeed: [Web Scraping With Scrapy and MongoDB](<https://devfeed.tech/articles/web-scraping-with-scrapy-and-mongodb-95799.md>)

Original publisher: [Read original article](<https://realpython.com/web-scraping-with-scrapy-and-mongodb/>)

Author: Martin Breuss

Published: 2026-10-22T14:00:00Z

Content type: tutorial

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [Web Scraping](<https://devfeed.tech/topics/web-scraping.md>), [MongoDB](<https://devfeed.tech/topics/mongodb.md>), [pymongo](<https://devfeed.tech/topics/pymongo.md>), [etl](<https://devfeed.tech/topics/etl.md>), [data-engineering](<https://devfeed.tech/topics/data-engineering.md>), [browser](<https://devfeed.tech/topics/browser.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [automated-testing](<https://devfeed.tech/tags/automated-testing.md>), [browser](<https://devfeed.tech/tags/browser.md>), [callback](<https://devfeed.tech/tags/callback.md>), [crawler](<https://devfeed.tech/tags/crawler.md>), [data](<https://devfeed.tech/tags/data.md>), [mongodb](<https://devfeed.tech/tags/mongodb.md>), [python](<https://devfeed.tech/tags/python.md>), [scraping](<https://devfeed.tech/tags/scraping.md>), [store](<https://devfeed.tech/tags/store.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [web](<https://devfeed.tech/tags/web.md>), [web-scraping](<https://devfeed.tech/tags/web-scraping.md>)

## AI overview

The tutorial builds a Scrapy crawler for Books to Scrape that extracts each book's title, price, and URL, follows pagination, and stores results in MongoDB through an item pipeline using PyMongo. It recommends relative CSS selectors and testing them in Scrapy's shell before writing the spider. To prevent duplicate records across runs, one pipeline option hashes each page URL into MongoDB's `_id` and drops existing items; this leaves existing records unchanged if their data later changes. The alternative uses `update_one` with `upsert=True` to insert or refresh records by URL, and requires dropping the existing collection when switching from timestamp-based IDs. The excerpt also covers configurable logging, request error callbacks, spider contracts, and unit tests. It assumes basic Python and HTML/CSS familiarity; the supplied text ends during the unit-testing section, so it does not establish the tutorial's full test implementation.

## Source excerpt

This tutorial covers how to write a Python web crawler using Scrapy to scrape and parse data, and then store the data in MongoDB.