Skip to main content

A downloader middleware that stores the current request chain to be crawled at another time.

Project description

scrapy-time-machine

PyPI PyPI - Python Version GitHub Workflow Status

Run your spider with a previously crawled request chain.

Install

pip install scrapy-time-machine

Why?

Lets say your spider crawls some page everyday and after some time you notice that an important information was added and you want to start saving it.

You may modify your spider and extract this information from now on, but what if you want the historical value of this data, since it was first introduced to the site?

With this extension you can save a snapshot of the site at every run to be used in the future (as long as you don't change the request chain).

Enabling

To enable this middlware, add this information to your projects's settings.py:

DOWNLOADER_MIDDLEWARES = {
    "scrapy_time_machine.timemachine.TimeMachineMiddleware": 901
}

TIME_MACHINE_ENABLED = True
TIME_MACHINE_STORAGE = "scrapy_time_machine.storages.DbmTimeMachineStorage"

Using

Store a snapshot of the current state of the site

scrapy crawl sample -s TIME_MACHINE_SNAPSHOT=true -s TIME_MACHINE_URI="/tmp/%(name)s-%(time)s.db"

This will save a snapshot at /tmp/sample-YYYY-MM-DDThh-mm-ss.db

Retrieve a snapshot from a previously saved state of the site

scrapy crawl sample -s TIME_MACHINE_RETRIEVE=true -s TIME_MACHINE_URI=/tmp/sample-YYYY-MM-DDThh-mm-ss.db

If no change was made to the spider between the current version and the version that produced the snapshot, the extracted items should be the same.

Sample project

There is a sample Scrapy project available at the examples directory.

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-time-machine-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

scrapy_time_machine-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file scrapy-time-machine-1.0.1.tar.gz.

File metadata

  • Download URL: scrapy-time-machine-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.5

File hashes

Hashes for scrapy-time-machine-1.0.1.tar.gz
Algorithm Hash digest
SHA256 10c7b6e6bd3c9aaecb04edbcd4e28e9944e7a826589c51e749b6d540befd25d1
MD5 dda3e76a24b46a57eec528ac342bbdba
BLAKE2b-256 b665a0b746ae0724d591ae23f2284295be2b31e417a934caee75c57ad1b96605

See more details on using hashes here.

File details

Details for the file scrapy_time_machine-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for scrapy_time_machine-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e8e82225cee9df88979afd3683636c55df514f17c3b4b1388dfd1577fd32bea
MD5 f21578c6b12040221d31e199e9342d50
BLAKE2b-256 b098f534e9b2c805da4090ed617c371057e5d33805038c8d7805d731f9792b75

See more details on using hashes here.

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