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.
Installation
Install scrapy-querycleaner using pip:
$ pip install scrapy-querycleaner
Configuration
Add QueryCleanerMiddleware by including it in SPIDER_MIDDLEWARES in your settings.py file:
SPIDER_MIDDLEWARES = { 'scrapy_querycleaner.QueryCleanerMiddleware': 100, }Here, priority 100 is just an example. Set its value depending on other middlewares you may have enabled already.
Enable the middleware using either QUERYCLEANER_REMOVE or QUERYCLEANER_KEEP (or both) in your setting.py.
Usage
At least one of the following settings needs to be present for the middleware to be enabled.
Supported settings
- QUERYCLEANER_REMOVE
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.)
- QUERYCLEANER_KEEP
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.
Example
Let’s suppose that the spider extracts URLs like:
http://www.example.com/product.php?pid=135&cid=12&ttda=12
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:
QUERYCLEANER_KEEP = '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.
Metadata
Release files for scrapy-querycleaner 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scrapy-querycleaner-1.0.0.tar.gz | 3.2 kB | Without provenance | Details for scrapy-querycleaner-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrapy_querycleaner-1.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for scrapy_querycleaner-1.0.0-py2.py3-none-any.whl |
Total release size: 7.0 kB
Release files / scrapy-querycleaner-1.0.0.tar.gz
| Download URL | scrapy-querycleaner-1.0.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f3fdc7558076e7a0dfdadb803d42661c372b75f05c436a7a721e28d16ec5d5a
|
|
BLAKE2b-256 checksum How to use checksums |
1915ede0e13684f7eb1d685e3428c78899408ffb72f4a63c613240feddbbb8af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / scrapy_querycleaner-1.0.0-py2.py3-none-any.whl
| Download URL | scrapy_querycleaner-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a40002384a277db89797fcf6c029bec46b05642c1e646f1476385b803745b333
|
|
BLAKE2b-256 checksum How to use checksums |
802aa3d6b7779dff0932017fcbfdad4b67b710160e524ac2914103ee963dee71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for scrapy-querycleaner 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.