Scrapy middleware is a framework of hooks into Scrapy’s spider processing mechanism where you can plug custom functionality to process the responses that are sent to Spiders for processing and to process the requests and items that are generated from spiders.
Scrapy also provides some built in Middlewares out of the box for use with your spiders.