scrapy-crawl-once
This package provides a Scrapy middleware which allows to avoid re-crawling pages which were already downloaded in previous crawls.
License is MIT.
Installation
pip install scrapy-crawl-once
Usage
To enable it, modify your settings.py:
SPIDER_MIDDLEWARES = {
# ...
'scrapy_crawl_once.CrawlOnceMiddleware': 100,
# ...
}
DOWNLOADER_MIDDLEWARES = {
# ...
'scrapy_crawl_once.CrawlOnceMiddleware': 50,
# ...
}
By default it does nothing. To avoid crawling a particular page multiple times set request.meta['crawl_once'] = True. When a response is received and a callback is successful, the fingerprint of such request is stored to a database. When spider schedules a new request middleware first checks if its fingerprint is in the database, and drops the request if it is there.
Other request.meta keys:
crawl_once_value - a value to store in DB. By default, timestamp is stored.
crawl_once_key - request unique id; by default request_fingerprint is used.
Settings
CRAWL_ONCE_ENABLED - set it to False to disable middleware. Default is True.
CRAWL_ONCE_PATH - a path to a folder with crawled requests database. By default .scrapy/crawl_once/ path inside a project dir is used; this folder contains <spider_name>.sqlite files with databases of seen requests.
CRAWL_ONCE_DEFAULT - default value for crawl_once meta key (False by default). When True, all requests are handled by this middleware unless disabled explicitly using request.meta['crawl_once'] = False.
Alternatives
https://github.com/scrapy-plugins/scrapy-deltafetch is a similar package; it does almost the same. Differences:
scrapy-deltafetch chooses whether to discard a request or not based on yielded items; scrapy-crawl-once uses an explicit request.meta['crawl_once'] flag.
scrapy-deltafetch uses bsddb3, scrapy-crawl-once uses sqlite.
Another alternative is a built-in Scrapy HTTP cache. Differences:
scrapy cache stores all pages on disc, scrapy-crawl-once only keeps request fingerprints;
scrapy cache allows a more fine grained invalidation consistent with how browsers work;
with scrapy cache all pages are still processed (though not all pages are downloaded).
Contributing
source code: https://github.com/TeamHG-Memex/scrapy-crawl-once
bug tracker: https://github.com/TeamHG-Memex/scrapy-crawl-once/issues
To run tests, install tox and run tox from the source checkout.
CHANGES
0.1.1 (2017-03-04)
new 'crawl_once/initial' value in scrapy stats - it contains the initial size (number of records) of crawl_once database.
0.1 (2017-03-03)
Initial release.
Metadata
Release files for scrapy-crawl-once 0.1.1
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-crawl-once-0.1.1.tar.gz | 5.1 kB | Without provenance | Details for scrapy-crawl-once-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrapy_crawl_once-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for scrapy_crawl_once-0.1.1-py2.py3-none-any.whl |
Total release size: 12.3 kB
Release files / scrapy-crawl-once-0.1.1.tar.gz
| Download URL | scrapy-crawl-once-0.1.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ab832ab5c4073ba2aa498a8c6bb2a792117ecd7deadca41d7fd1cdee534caf4
|
|
BLAKE2b-256 checksum How to use checksums |
fce3e196d13482add6f506976e92fca549f3bfdeb5a015a5dc5146cfacd30d32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / scrapy_crawl_once-0.1.1-py2.py3-none-any.whl
| Download URL | scrapy_crawl_once-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
60ea4e7529f99ad1ec6cacbad53828fbfa5959cc4dddfe8047557e7c189e920c
|
|
BLAKE2b-256 checksum How to use checksums |
49978684f7a85d6be3a52f50cce2411eaaaf6c4e0d6c1598fa7b4e99578ba2cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for scrapy-crawl-once 0.1.1
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.