Skip to main content

An alternative to the built-in ItemLoader of Scrapy which focuses on maintainability of fallback parsers.

Project description

https://img.shields.io/pypi/pyversions/scrapy-loader-upkeep.svg https://img.shields.io/pypi/v/scrapy-loader-upkeep.svg https://travis-ci.org/BurnzZ/scrapy-loader-upkeep.svg?branch=master

Overview

This improves over the built-in ItemLoader of Scrapy by adding features that focuses on the maintainability of the spider over time.

This allows developers to keep track of how often parsers are being used on a crawl, allowing to safely remove obsolete css/xpath fallback rules.

Motivation

Scrapy supports adding multiple css/xpath rules in its ItemLoader by default in order to provide a convenient way for developers to keep up with site changes.

However, some sites change layouts more often than others, while some perform A/B tests for weeks/months where developers need to accommodate those changes.

These fallback css/xpath rules gets obsolete quickly and fills up the project with potentially dead code, posing a threat to the spiders’ long term maintenance.

Original idea proposal: https://github.com/scrapy/scrapy/issues/3795

Usage

from scrapy_loader_upkeep import ItemLoader

class SiteItemLoader(ItemLoader):
    pass

Using it inside a spider callback would look like:

def parse(self, response):
    loader = SiteItemLoader(response=response, stats=self.crawler.stats)

Nothing would change in the usage of this ItemLoader except for the part on injecting stat dependency to it, which is necessary to keep track of the usage of the parser rules.

Spider Example

This is taken from the examples/ directory.

$ scrapy crawl quotestoscrape_simple_has_missing

This should output in the stats:

2019-06-16 14:32:32 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{ ...
  'parser/QuotesItemLoader/author/css/1': 10,
  'parser/QuotesItemLoader/quote/css/1/missing': 10,
  'parser/QuotesItemLoader/quote/css/2': 10
  ...
}

In this example, we could see that the 1st css rule for the quote field has had instances of not being matched at all during the scrape.

Requirements

Python 3.6+

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-loader-upkeep-0.1a2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

scrapy_loader_upkeep-0.1a2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file scrapy-loader-upkeep-0.1a2.tar.gz.

File metadata

  • Download URL: scrapy-loader-upkeep-0.1a2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4

File hashes

Hashes for scrapy-loader-upkeep-0.1a2.tar.gz
Algorithm Hash digest
SHA256 4381bfdfca67faab40a44867957fdd6ae2739750c724ff1faaff7387d4a5510f
MD5 8aa8a5d8eda30fdcee7e36255c17f180
BLAKE2b-256 4014b7c35d088630c6eac5afb0aa4bb61ca9203766730cf1a8b0e6b8c3791f54

See more details on using hashes here.

Provenance

File details

Details for the file scrapy_loader_upkeep-0.1a2-py3-none-any.whl.

File metadata

  • Download URL: scrapy_loader_upkeep-0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4

File hashes

Hashes for scrapy_loader_upkeep-0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 f2f6bb05f4f712fcb588111a5b28e0041a9a7e85bd35a798bc5d9f4531f5e541
MD5 64482259e3b26ed3c4adb7ba517a7bfa
BLAKE2b-256 f54f2b8040a2215436ccf18dc27dd95696e4273a4f5eb65dcc1cac068fe41817

See more details on using hashes here.

Provenance

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