Meeseeks v0.1.0 Meeseeks

# Fetch HTML with your preferred library
html = Tesla.get("https://news.ycombinator.com/").body

# Select stories and return a map containing the title and url of each
for story <- Meeseeks.all(html, "tr.athing") do
  title_a = Meeseeks.one(story, ".title a")
  %{:title => Meeseeks.text(title_a),
    :url => Meeseeks.attr(title_a, "href")}
end

#=> [%{:title => "...", :url => "..."}, %{:title => "...", :url => "..."}, ...]

Summary

Functions

Returns a Result for each node in the queryable matching a selector

Returns Result’s value for the attribute or nil

Returns Result’s attribute vector or nil

Returns the combined data (contents of script and style tags) of Result and its children, which may be an empty string

Returns a Result for the first node in the queryable (depth-first) matching a selector

Parses a source (HTML string or tuple-tree) into a Document

Returns Result’s tag or nil

Returns the combined text of Result and its children, which may be an empty string

Returns a tuple-tree representing Result and its children

Types

queryable()
queryable() :: source | Meeseeks.Document.t | Meeseeks.Result.t
selectors()
selectors() :: String.t | [Meeseeks.Selector.t]
source()
source() :: String.t | Meeseeks.TupleTree.t

Functions

all(queryable, selectors)
all(queryable, selectors) :: [Meeseeks.Result.t]

Returns a Result for each node in the queryable matching a selector.

Examples

iex> Meeseeks.all("<div id=main><p>1</p><p>2</p><p>3</p></div>", "#main p")
[%Meeseeks.Result{...}, %Meeseeks.Result{...}, %Meeseeks.Result{...}]
attr(result, attribute)
attr(Meeseeks.Result.t, String.t) :: String.t | nil

Returns Result’s value for the attribute or nil.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.attr(result, "id")
"example"
attrs(result)
attrs(Meeseeks.Result.t) :: [{String.t, String.t}] | nil

Returns Result’s attribute vector or nil.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.attrs(result)
[{"id", "example"}]
data(result)
data(Meeseeks.Result.t) :: String.t

Returns the combined data (contents of script and style tags) of Result and its children, which may be an empty string.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.data(result)
""
iex> result = Meeseeks.one("<script id=example>Hi</script>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.data(result)
"Hi"
one(queryable, selectors)
one(queryable, selectors) :: Meeseeks.Result.t

Returns a Result for the first node in the queryable (depth-first) matching a selector.

Examples

iex> Meeseeks.one("<div id=main><p>1</p><p>2</p><p>3</p></div>", "#main p")
%Meeseeks.Result{...}
parse(source)
parse(source) :: Meeseeks.Document.t

Parses a source (HTML string or tuple-tree) into a Document.

Examples

iex> Meeseeks.parse("<div id=main><p>Hello, Meeseeks!</p></div>")
%Meeseeks.Document{...}
iex> Meeseeks.parse({"div", [{"id", "main"}], [{"p", [], ["Hello, Meeseeks!"]}]})
%Meeseeks.Document{...}
tag(result)
tag(Meeseeks.Result.t) :: String.t | nil

Returns Result’s tag or nil.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.tag(result)
"div"
text(result)
text(Meeseeks.Result.t) :: String.t

Returns the combined text of Result and its children, which may be an empty string.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.text(result)
"Hi"
tree(result)
tree(Meeseeks.Result.t) :: Meeseeks.TupleTree.node_t

Returns a tuple-tree representing Result and its children.

If Result is a Text or Data node, returns their string value.

Examples

iex> result = Meeseeks.one("<div id=example>Hi</div>", "#example")
%Meeseeks.Result{...}
iex> Meeseeks.tree(result)
{"div", [{"id", "example"}], ["Hi"]}