Skip to main content

A lightweight parser with XPath support, Scrapy-like Items, and flexible output options.

Project description

lightparser

A lightweight parsing library inspired by Scrapy.

Features

  • Scrapy-like 'Selector' object for Xpath parsing.
  • Lightweight 'Item' class for structured data.
  • Automatic CSV/JSON export via '-o' or '-O' argument.
  • '-O' argument to overwrite the existing file.
  • '-o' argument to append the existing file.
  • No framework lock-in.

Installation

pip install lightparser

Usage

import requests
from lightparser import Selector, Item, yield_item

response = requests.get("https://example.com")
selector = Selector(response.text)

for product in selector.xpath('//div[@class="product"]'):
    item = Item()
    item["title"] = product.xpath(".//h2/text()").get()
    item["price"] = product.xpath(".//span[@class='price']/text()").get()
    yield_item(item)

Command-line Usage

python my_script.py -o output.csv

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

lightparser-0.1.4.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightparser-0.1.4-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file lightparser-0.1.4.tar.gz.

File metadata

  • Download URL: lightparser-0.1.4.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for lightparser-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a0f42da504186ebf6e64d51be889083950358f9615f4d74d52bfaa0b902906cb
MD5 fb018d0eeb818ba80a6cc2c5853e408d
BLAKE2b-256 54fb1f89d6a1fa48776752bfa3e3c56203792090e3c2cb9c510f32125b03a072

See more details on using hashes here.

File details

Details for the file lightparser-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: lightparser-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for lightparser-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8b147c1c91ca1947ef974040afc4549917cc5b6bd6df1cd32f0d9aad5d516c
MD5 3c5770090a1d7ca5ae97b5f73ca2e41a
BLAKE2b-256 fcd94dce2fd2f60563635d20a33cfaef68e4c31754c17b69e047e9878aab6914

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