Skip to main content

Scrapy spider middleware to clean up query parameters in request URLs

Project description

This is a Scrapy spider middleware to clean up the request URL GET query parameters at the output of the spider in accordance with the patterns provided by the user.


Install scrapy-querycleaner using pip:

$ pip install scrapy-querycleaner


  1. Add QueryCleanerMiddleware by including it in SPIDER_MIDDLEWARES in your file:

        'scrapy_querycleaner.QueryCleanerMiddleware': 100,

    Here, priority 100 is just an example. Set its value depending on other middlewares you may have enabled already.

  2. Enable the middleware using either QUERYCLEANER_REMOVE or QUERYCLEANER_KEEP (or both) in your


At least one of the following settings needs to be present for the middleware to be enabled.

Supported settings


a pattern (regular expression) that a query parameter name must match in order to be removed from the URL. (All the others will be accepted.)


a pattern that a query parameter name must match in order to be kept in the URL. (All the others will be removed.)

You can combine both if some query parameters patterns should be kept and some should not.

The remove pattern has precedence over the keep one.


Let’s suppose that the spider extracts URLs like:

and we want to leave only the parameter pid.

To achieve this objective we can use either QUERYCLEANER_REMOVE or QUERYCLEANER_KEEP:

  • In the first case, the pattern would be cid|ttda:

    QUERYCLEANER_REMOVE = 'cid|ttda'
  • In the second case, pid:


The best solution depends on a particular case, that is, how the query filters will affect any other URL that the spider is expected to extract.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy-querycleaner-1.0.0.tar.gz (3.2 kB view hashes)

Uploaded source

Built Distribution

scrapy_querycleaner-1.0.0-py2.py3-none-any.whl (3.8 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page