8000 GitHub - afthill/libextract: Process and extract data from HT/XML using small, pipelined functions!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Process and extract data from HT/XML using small, pipelined functions!

License

Notifications You must be signed in to change notification settings

afthill/libextract

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libextract: simple data extraction

https://travis-ci.org/datalib/libextract.svg?branch=master
    ___ __              __                  __
   / (_) /_  ___  _  __/ /__________ ______/ /_
  / / / __ \/ _ \| |/_/ __/ ___/ __ `/ ___/ __/
 / / / /_/ /  __/>  </ /_/ /  / /_/ / /__/ /_
/_/_/_.___/\___/_/|_|\__/_/   \__,_/\___/\__/

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

Overview

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 rodricios.github.io/eatiht 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).

Installation

pip install libextract

Usage

Extracting text-nodes from a wikipedia page:

from requests import get
from libextract.api import articles

r = get('http://en.wikipedia.org/wiki/Information_extraction')
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("http://en.wikipedia.org/wiki/Human_height")
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][0])
{'Entity': ['Monaco',
  'Macau',
  'Japan',
  'Singapore',
  'San Marino',
  ...}

Dependencies

lxml
statscounter

Disclaimer

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

:)

About

Process and extract data from HT/XML using small, pipelined functions!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.2%
  • HTML 3.8%
0