Skip to main content

A declarative html scraper for python. Define your scraper spec in a yaml or json to extract data from html documents.

Project description

A Declarative HTML Scraper for Python

This package provides a simple way to declare what data should be extracted from an HTML document in a configuration file.

This enables sharing of scraping logic across projects and teams without the risk of executing untrusted code. It also allows for easier maintenance and updates to scraping logic without needing to modify the underlying codebase.

CLI

The package includes a Click-based CLI with two commands:

spextract parse spec.yaml <path to html file or directory>
spextract validate spec.yaml expected-results.yaml

parse emits YAML in the same expected-results format used by validate, so you can capture known-good output and re-run validation later.

How to use

Build a configuration file

You can write a configuration file with the provided ParserSpec class.

import spextract

spec = spextract.ParserSpec(
    name="example_parser",
    description="An example parser for demonstration purposes.",
    fields=[
        spextract.FieldSpec(
            name="title",
            selector="h1.title::text",
            type=spextract.FieldType.TEXT,
        ),
        spextract.FieldSpec(
            name="links",
            selector="a.link::attr(href)",
            type=spextract.FieldType.LINK,
            multiple=True,
        ),
        spextract.FieldSpec(
            name="author",
            selector="div.author",
            type=spextract.FieldType.OBJECT,
            fields=[
                spextract.FieldSpec(
                    name="name",
                    selector="span.name::text",
                    type=spextract.FieldType.TEXT,
                ),
                spextract.FieldSpec(
                    name="profile_url",
                    selector="a.profile::attr(href)",
                    type=spextract.FieldType.LINK,
                ),
            ]
        ),
    ]
)

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

spextract-0.6.6.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spextract-0.6.6-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file spextract-0.6.6.tar.gz.

File metadata

  • Download URL: spextract-0.6.6.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spextract-0.6.6.tar.gz
Algorithm Hash digest
SHA256 d623331bcfab671cf25a014f49a67a0a94cf47cc10f5ce251fe14c04b96b607d
MD5 2b679cc3d9a8d01079295a2e03c1595f
BLAKE2b-256 dbb945d1fc63891a815c1bc720f8a9d8d446fd21fbc81a87a900a7e6a78ccbf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for spextract-0.6.6.tar.gz:

Publisher: ci.yml on vincentropy/declarative_scraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spextract-0.6.6-py3-none-any.whl.

File metadata

  • Download URL: spextract-0.6.6-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spextract-0.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7d478db7ac18e20542b8891703a62d0e8737a1672bdbb1a355313fd31dba248c
MD5 452789a9a319ca26fe1bf7e29abe884f
BLAKE2b-256 203d4ce1e349ecc84cb0ce2f5f60970bf8ccd21e7903b1cd339b3c2cf3b0bd35

See more details on using hashes here.

Provenance

The following attestation bundles were made for spextract-0.6.6-py3-none-any.whl:

Publisher: ci.yml on vincentropy/declarative_scraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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