Skip to main content

xpath-filter

version tests

Filter HTML files using xpath mappings.

Installation

Install xpath-filter using pip:

pip install xpath-filter

Usage

Import the xpath_filter function from the xpath_filter module. Find below some use cases.

Filtering HTML file

>>> xpaths = {
...     'article': {
...         'xpath': '//div[@class="article"]',
...         'matches': 'all',
...         'elements': {
...             'author': './@data-author',
...             'content': './p/text()'
...         }
...     }
... }
>>> xpath_filter('index.html', xpaths)

Result

{'article': [{'author': 'Ana', 'Content': 'Awesome'}, {'author': 'Bob', 'Content': 'Bad'}]}

Filtering HTML file from a YAML xpaths definition.

File at "xpaths.yml":

article:
    xpath: //div[@class="article"]
    matches: all
    elements:
        author: './@data-author'
        content: ./p/text()

Code:

>>> xpath_filter('index.html', 'xpaths.yml')

Result

{'article': [{'author': 'Ana', 'Content': 'Awesome'}, {'author': 'Bob', 'Content': 'Bad'}]}

Simplified filtering

By definining only the xpath of an HTML element, only its first match is returned and no inner element is searched.

>>> xpath_filter('index.html', {'article': '//div[@class="article"]'})
>>> xpath_filter('index.html', {'article': '//div[@class="article"]/p/text()'})

Result

{'article': <Element div at 0x1f08369ea80>}
{'article': 'Awesome'}

Metadata

Release files for xpath-filter 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xpath-filter 1.0.1
File Size Uploaded Provenance Actions
xpath_filter-1.0.1.tar.gz 7.5 kB Without provenance Details for xpath_filter-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xpath-filter 1.0.1
File Interpreter ABI Platform Actions
xpath_filter-1.0.1-py3-none-any.whl Python 3 none any Details for xpath_filter-1.0.1-py3-none-any.whl

Total release size: 15.7 kB

Release files / xpath_filter-1.0.1.tar.gz

Download URL xpath_filter-1.0.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
625273246a4b97980e6bfdf769b9277c64c05864b6f51ee5bca24ae2adc1b373
BLAKE2b-256 checksum
How to use checksums
4a7f9c62aaede6a3600b8e94e75bcbeadc560a046a6e0cc8b82c4c0e672a227a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / xpath_filter-1.0.1-py3-none-any.whl

Download URL xpath_filter-1.0.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c84c6c811675fc8ec4bb3c92a5ffe55af5400e2706841e752534742d98d20a8c
BLAKE2b-256 checksum
How to use checksums
47968af617a83bf5a9e519ea8d97d892cd829da66885da262482c8d72c92db81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for xpath-filter 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page