Skip to main content

Making parsing concise

Project description

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 ;)

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

parsechain-0.0.3.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file parsechain-0.0.3.tar.gz.

File metadata

  • Download URL: parsechain-0.0.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for parsechain-0.0.3.tar.gz
Algorithm Hash digest
SHA256 54c0210d7be46b1cce64973b64784cbb63287efce755b8ee9095f93ff07f1274
MD5 057267663dfdeecd98263add64a4e6c0
BLAKE2b-256 694f09ccf5e5bfa64a55b83fd99babb4bb1a4cce90a3cc321b13aa337fd1fa46

See more details on using hashes here.

Supported by

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