All Projects → alan-turing-institute → ReadabiliPy

alan-turing-institute / ReadabiliPy

Licence: MIT License
A simple HTML content extractor in Python. Can be run as a wrapper for Mozilla's Readability.js package or in pure-python mode.

Programming Languages

HTML
75241 projects
python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ReadabiliPy

SAPC-APCA
APCA (Accessible Perceptual Contrast Algorithm) is a new method for predicting contrast for use in emerging web standards (WCAG 3) for determining readability contrast. APCA is derived form the SAPC (S-LUV Advanced Predictive Color) which is an accessibility-oriented color appearance model designed for self-illuminated displays.
Stars: ✭ 266 (+383.64%)
Mutual labels:  readability
automated-readability
Formula to detect ease of reading according to the Automated Readability Index (1967)
Stars: ✭ 46 (-16.36%)
Mutual labels:  readability
lorca
Natural Language Processing for Spanish in Node.js. Stemmer, sentiment analysis, readability, tf-idf with batteries, concordance and more!
Stars: ✭ 95 (+72.73%)
Mutual labels:  readability
dale-chall-formula
Formula to find the grade level according to the (revised) Dale–Chall Readability Formula (1995)
Stars: ✭ 26 (-52.73%)
Mutual labels:  readability
distinctipy
A lightweight package for generating visually distinct colours.
Stars: ✭ 125 (+127.27%)
Mutual labels:  hut23
rePocketable
Tool to fetch articles from (getPocket|the web) and turn them into epub
Stars: ✭ 49 (-10.91%)
Mutual labels:  readability
trafilatura
Python & command-line tool to gather text on the Web: web crawling/scraping, extraction of text, metadata, comments
Stars: ✭ 711 (+1192.73%)
Mutual labels:  readability
TuringDataStories
TuringDataStories: An open community creating “Data Stories”: A mix of open data, code, narrative 💬, visuals 📊📈 and knowledge 🧠 to help understand the world around us.
Stars: ✭ 27 (-50.91%)
Mutual labels:  hut23
ptype
Probabilistic type inference
Stars: ✭ 25 (-54.55%)
Mutual labels:  hut23
hast-util-reading-time
utility to estimate the reading time
Stars: ✭ 55 (+0%)
Mutual labels:  readability
flesch
Formula to detect the ease of reading a text according to Flesch Reading Ease (1975)
Stars: ✭ 25 (-54.55%)
Mutual labels:  readability
react-native-reader
Cross-platform native reader mode for react-native (safari like)
Stars: ✭ 52 (-5.45%)
Mutual labels:  readability
gunning-fog
Formula to detect the ease of reading a text according to the Gunning fog index (1952)
Stars: ✭ 16 (-70.91%)
Mutual labels:  readability
Vyxal
A golfing language that has aspects of traditional programming languages - terse, elegant, readable.
Stars: ✭ 134 (+143.64%)
Mutual labels:  readability
readability
readability for golang. 网页文章标题和正文抽取工具
Stars: ✭ 30 (-45.45%)
Mutual labels:  readability
twitter-to-rss
Simple python script to parse twitter feed to generate a rss feed.
Stars: ✭ 15 (-72.73%)
Mutual labels:  readability
pypely
Make your data processing easy
Stars: ✭ 17 (-69.09%)
Mutual labels:  readability
readability-extractor
Javascript/Node wrapper around Mozilla's Readability library so that ArchiveBox can call it as a oneshot CLI command to extract each page's article text.
Stars: ✭ 18 (-67.27%)
Mutual labels:  readability
eslint-plugin-lodash-template
ESLint plugin for John Resig-style micro template, Lodash's template, Underscore's template and EJS.
Stars: ✭ 15 (-72.73%)
Mutual labels:  readability
AIrsenal
Machine learning Fantasy Premier League team
Stars: ✭ 140 (+154.55%)
Mutual labels:  hut23

ReadabiliPy

Build Status Coverage Status

ReadabiliPy contains a Python wrapper for Mozilla's Readability.js Node.js package, as well as article extraction routines written in pure Python.

This package augments the output of Readability.js to also return a list of plain text representations of article paragraphs.

ReadabiliPy comes with a handy command line application: readabilipy.

Installation

To use the Readability.js wrapper you need to have a working Node.js installation of version 10 or higher. Make sure to install Node.js before installing this package, as this ensures Readability.js will be installed. If you only want to use the Python-based article extraction, you do not need to install Node.js.

ReadabiliPy can be installed simply from PyPI:

$ pip install readabilipy

Note that to update to a new version of Readability.js you can simply reinstall ReadabiliPy.

Usage

ReadabiliPy can be used either as a command line application or as a Python library.

Command line application

The readabilipy command line application can be used to extract an article from an HTML source file.

For example, if you have the article saved as input.html in the current directory then you can run:

$ readabilipy -i ./input.html -o article.json

The extracted article can then be found in the article.json file. By default ReadabiliPy will use the Readability.js functionality to extract the article, provided this is available. If instead you'd like to use the Python-based extraction, run:

$ readabilipy -p -i ./input.html -o article.json

The complete help text of the command line application is as follows:

$ readabilipy -h
usage: readabilipy [-h] -i INPUT_FILE -o OUTPUT_FILE [-c] [-n] [-p] [-V]

Extract article data from a HTML file using either Mozilla's Readability.js
package or a simplified python-only alternative.

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT_FILE, --input-file INPUT_FILE
                        Path to input file containing HTML.
  -o OUTPUT_FILE, --output-file OUTPUT_FILE
                        Path to file to output the article data to as JSON.
  -c, --content-digests
                        Add a 'data-content-digest' attribute containing a
                        SHA256-based digest of the element's contents to each
                        HTML element in the plain_content output.
  -n, --node-indexes    Add a 'data-node-index' attribute containing a
                        hierarchical representation of the element's position
                        in the HTML structure each HTML element in the
                        plain_content output.
  -p, --use-python-parser
                        Use the pure-python 'plain_html' parser included in
                        this project rather than Mozilla's Readability.js.
  -V, --version         Show version and exit

Library

ReadabiliPy can also be used as a Python package. The main routine is called simple_json_from_html_string and expects the HTML article as a string. Here is an example of extracting an article after downloading the page using requests:

>>> import requests
>>> from readabilipy import simple_json_from_html_string
>>> req = requests.get('https://en.wikipedia.org/wiki/Readability')
>>> article = simple_json_from_html_string(req.text, use_readability=True)

Note that you need to use the flag use_readability=True to use Readability.js, otherwise the Python-based extraction is used.

The simple_json_from_html_string function returns a dictionary with the following fields:

  • title: The article title
  • byline: Author information
  • content: A simplified HTML representation of the article, with all article text contained in paragraph elements.
  • plain_content: A "plain" version of the simplified Readability.js article HTML present in the content field. This attempts to retain only the plain text content of the article, while preserving the HTML structure.
  • plain_text: A list containing plain text representations of each paragraph (<p>) or list (<ol> or <ul>) present in the simplified Readability.js article HTML in the content field. Each paragraph or list is represented as a single string. List strings look like "* item 1, * item 2, * item 3," for both ordered and unordered lists (note the trailing ,).

Note further that:

  • All fields are guaranteed to be present. If individual fields are missing from the output of Readability.js, the value of these fields will be None. If no article data is returned by Readability.js, the value of all fields will be None.
  • All text in the plain_content and plain_text fields is encoded as unicode normalised using the "NFKC" normal form. This normal form is used to try and ensure as much as possible that things that appear visually the same are encoded with the same unicode representation (the K part) and characters are represented as a single composite character where possible (the C part).
  • An optional content_digests flag can be passed to the Python wrapper. When this is set to True, each HTML element in the plain_content field has a data-content-digest attribute, which holds the SHA-256 hash of its plain text content. For "leaf" nodes (containing only plain text in the output), this is the SHA-256 hash of their plain text content. For nodes containing other nodes, this is the SHA-256 hash of the concatenated SHA-256 hashes of their child nodes.
  • An optional node_indexes flag can be passed to the Python wrapper. When this is set to True, each HTML element in the plain_content field has a data-node-indexes attribute, which holds a hierarchical index describing the location of element within the plain_content HTML structure.
  • An optional use_readability flag can be passed to the Python wrapper. When this is set to True, Mozilla's Readability.js will be used as the parser. If it is set to False then the pure-python parser in plain_html.py will be used instead.

The second top-level function exported by ReadabiliPy is simple_tree_from_html_string. This returns a cleaned, parsed HTML tree of the article as a BeautifulSoup object.

Notes

License: MIT License, see the LICENSE file.

Copyright (c) 2018, The Alan Turing Institute

If you encounter any issues or have any suggestions for improvement, please open an issue on Github. You're helping to make this project better for everyone!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].