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:

decs parse spec.yaml <path to html file or directory>
decs 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 py_decs

spec = py_decs.ParserSpec(
    name="example_parser",
    description="An example parser for demonstration purposes.",
    fields=[
        py_decs.FieldSpec(
            name="title",
            selector="h1.title::text",
            type=py_decs.FieldType.TEXT,
        ),
        py_decs.FieldSpec(
            name="links",
            selector="a.link::attr(href)",
            type=py_decs.FieldType.LINK,
            multiple=True,
        )
        py_decs.FieldSpec(
            name="author",
            selector="div.author",
            type=py_decs.FieldType.OBJECT,
            fields=[
                py_decs.FieldSpec(
                    name="name",
                    selector="span.name::text",
                    type=py_decs.FieldType.TEXT,
                ),
                py_decs.FieldSpec(
                    name="profile_url",
                    selector="a.profile::attr(href)",
                    type=py_decs.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.1.tar.gz (13.5 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.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spextract-0.6.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for spextract-0.6.1.tar.gz
Algorithm Hash digest
SHA256 ce0943dad930a532e8ae27dd494aa82ec55962841cd037bf14f550e133b9c1ce
MD5 d8fc6865b5abe0b7e5cef72f92f03f4b
BLAKE2b-256 a68f0e455cb67374f27ecab9ed4cf1b46b8a82a71396b916f80dbf4924cf7979

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spextract-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for spextract-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9902744d2fcb0b511a68c31199fb4a3ac6c8de8add1e1058115a3db4d04792
MD5 dd49a3b3987b564e10f89950a3ee591a
BLAKE2b-256 af9cca49b4aa48153ee46338beeaa96154261d874dbce479e2125437698d8f87

See more details on using hashes here.

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