A declarative html scraper for python
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spextract-0.5.16.tar.gz.
File metadata
- Download URL: spextract-0.5.16.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3b8a76aa8202b1e60251d0a6e1770054bd0cd569d7c25d69a1f484469dadebc
|
|
| MD5 |
7560928d4b17e0082e45349ef085288a
|
|
| BLAKE2b-256 |
7a76b855d41792248dad43bfde20c3e636811d0247e095eafd8b89f417aca9f1
|
File details
Details for the file spextract-0.5.16-py3-none-any.whl.
File metadata
- Download URL: spextract-0.5.16-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09787ae10cb0487fd2f836ded2e668588ca5067142f641bf107bfdebb6862198
|
|
| MD5 |
78563ab881ef7b4657fc536a6fffd327
|
|
| BLAKE2b-256 |
4c4915ad0d090fa6f3f995a358ea1d3ecee200254b13da1550bde08f78b4fc27
|