Skip to main content

A way to parse html fluently and as declarative as possible. This is in alpha stage now, things will change.

Installation

pip install parsechain

Usage

import requests
from parsechain import C, Response

# Fetch html and cast it
response = Response.cast(requests.get(...))

# Get a movie title and rating
title = response.css('h1 .title').text
rating = response.css('.left-box').inner_text.re(r'IMDb: ([\d.]+)').float

# Or both
movie = response.root.multi({
    'title': C.css('h1 .title').text,
    'rating': C.css('.left-box').inner_text.re(r'IMDb: ([\d.]+)').float,
})

The last example could be extended to show chains reuse:

def by_label(label):
    return C.css('.left-box').inner_text.re(fr'{label}: ([\w.]+)')

parse_movie = C.multi({
    'title': C.css('h1 .title').text,
    'rating': by_label('IMDb').float,
    'status': by_label('Status').trim,
})

movie = parse_movie(response.root)  # Pass a root of a tree

The complete list of available ops could be seen in parsechain.chains.Ops class. Proper documentation to follow, some day ;)

Metadata

Release files for parsechain 0.0.3

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

Source distribution (sdist)

Source distribution for parsechain 0.0.3
File Size Uploaded
parsechain-0.0.3.tar.gz 8.0 kB Details

Release files / parsechain-0.0.3.tar.gz

Download URL parsechain-0.0.3.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
54c0210d7be46b1cce64973b64784cbb63287efce755b8ee9095f93ff07f1274
BLAKE2b-256 checksum
How to use checksums
694f09ccf5e5bfa64a55b83fd99babb4bb1a4cce90a3cc321b13aa337fd1fa46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

0.0.2

2 release files

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