Skip to main content

A HT/XML web scraping tool

Project description
    ___ __              __                  __
   / (_) /_  ___  _  __/ /__________ ______/ /_
  / / / __ \/ _ \| |/_/ __/ ___/ __ `/ ___/ __/
 / / / /_/ /  __/>  </ /_/ /  / /_/ / /__/ /_
/_/_/_.___/\___/_/|_|\__/_/   \__,_/\___/\__/

Libextract is a statistics-enabled extraction library that works on HTML and XML documents, written in Python and originating from eatiht.


Libextract provides two extractors out-of-the-box: api.articles and api.tabular

libextract.api.articles(document, encoding=’utf-8’, count=5)

Given an html document, and optionally the encoding and the number of predictions (count) to return (in descending rank), articles returns a list of HTML-nodes likely containing the articles of text of a given website.

The extraction algorithm is based of text length. Refer to for an in-depth explanation.

libextract.api.tabular(document, encoding=’utf-8’, count=5)

Given an html document, and optionally the encoding, and the number of predictions (count) to return (in descending rank) tabular returns a list of HTML nodes likely containing “tabular” data (ie. table, and table-like elements).


pip install libextract


Extracting text-nodes from a wikipedia page:

from requests import get
from libextract.api import articles

r = get('')
textnodes = articles(r.content)

Libextract uses Python’s de facto HT/XML processing library, lxml.

The predictions returned by both api.articles and api.tabular are lxml HtmlElement objects (along with the associated metric used to rank each prediction).

Therefore, you can access lxml’s methods for post-processing.

>> print(textnodes[0][0].text_content())
Information extraction (IE) is the task of automatically extracting structured information...

Tabular-data extraction is just as easy.

from libextract.api import tabular

height_data = get("")
tabs = tabular(height_data.content)

To convert HT/XML element to python dict (and, you know, use it with Pandas and stuff):

>>> from libextract import clean
>>> clean.to_dict(tabs[0])
{'Entity': ['Monaco',
  'San Marino',




This project is still in its infancy; and advice and suggestions as to what this library could and should be would be greatly appreciated


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 (46.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page