Readability (readability v0.13.0)

View Source

Readability library for extracting & curating articles.

Example

@type html :: binary

# Just pass url
%Readability.Summary{title: title, authors: authors, article_html: article} = Readability.summarize(url)

# Extract title
Readability.title(html)

# Extract published at
Readability.published_at(html)

# Extract authors.
Readability.authors(html)

# Extract only text from article
article = html
          |> Readability.article
          |> Readability.readable_text

# Extract article with transformed html
article = html
          |> Readability.article
          |> Readability.raw_html

Summary

Functions

Using a variety of metrics (content score, classname, element types), find the content that is most likely to be the stuff a user wants to read.

Extract authors.

Returns true if Content-Type in provided headers list is a markup type, else false.

Extract MIME Type from headers.

parse(raw_html) deprecated

Extract published_at

Returns raw HTML binary from html_tree.

Returns attributes, tags cleaned HTML.

Returns only text binary from html_tree.

Summarize the primary readable content of a webpage.

Extract title

Types

headers()

@type headers() :: list()[tuple()]

html_tree()

@type html_tree() :: tuple() | list()

options()

@type options() :: list()

raw_html()

@type raw_html() :: binary()

url()

@type url() :: binary()

Functions

article(raw_html, opts \\ [])

@spec article(binary(), options()) :: html_tree()

Using a variety of metrics (content score, classname, element types), find the content that is most likely to be the stuff a user wants to read.

Example

iex> article_tree = Redability(html_str)
# returns article that is tuple

authors(html)

@spec authors(binary() | html_tree()) :: list()[binary()]

Extract authors.

Example

iex> authors = Readability.authors(html_str)
["José Valim", "chrismccord"]

default_options()

is_response_markup(headers)

@spec is_response_markup(headers()) :: boolean()

Returns true if Content-Type in provided headers list is a markup type, else false.

Example

iex> Readability.is_response_markup?([{"Content-Type", "text/html"}])
true

mime(headers \\ [])

@spec mime(headers()) :: String.t()

Extract MIME Type from headers.

Example

iex> mime = Readability.mime(headers_list)
"text/html"

parse(raw_html)

This function is deprecated. Use `Floki.parse_document/1` or `Floki.parse_fragment/1` instead..

published_at(raw_html)

@spec published_at(binary() | html_tree()) ::
  %DateTime{
    calendar: term(),
    day: term(),
    hour: term(),
    microsecond: term(),
    minute: term(),
    month: term(),
    second: term(),
    std_offset: term(),
    time_zone: term(),
    utc_offset: term(),
    year: term(),
    zone_abbr: term()
  }
  | %Date{calendar: term(), day: term(), month: term(), year: term()}
  | nil

Extract published_at

Example

iex> datetime = Readability.published_at(html_str)
%DateTime{}

raw_html(html_tree)

@spec raw_html(html_tree()) :: binary()

Returns raw HTML binary from html_tree.

readable_html(html_tree)

@spec readable_html(html_tree()) :: binary()

Returns attributes, tags cleaned HTML.

readable_text(html_tree)

@spec readable_text(html_tree()) :: binary()

Returns only text binary from html_tree.

regexes(arg1)

summarize(url, opts \\ [])

@spec summarize(url(), options()) :: Readability.Summary.t()

Summarize the primary readable content of a webpage.

title(raw_html)

@spec title(binary() | html_tree()) :: binary()

Extract title

Example

iex> title = Readability.title(html_str)
"Some title in html"