Exquery.Query
SourceSummary↑
all(tree, spec) | Find the all elements in the tree that matche the spec |
apply_ids(tree) | |
apply_ids(list1, acc, idx) | |
before(tree, spec, offset) | Find the element before the specified element |
css(tree, selection) | Find the element by css id or class. More complex selections are a wip |
css_to_spec(css) | |
css_to_spec(arg1, acc, qualifiers) | |
next(tree, spec, offset) | Find the element after the specified element |
normalize_css(css) | |
one(tree, spec) | Find the first element in the tree that matches the spec |
unapply_ids(tree) | |
unapply_ids(list1, acc) |
Functions
Find the all elements in the tree that matche the spec.
A tree is an HTML tree given from Exquery.tree/1
A spec is an HTML elemement, which a three element tuple
of the element type, contents, and attributes.
<div id="foo"></div>
would look like {:tag, "div", [{"id", "foo"}]}
You may pass :any
in for the element type and element contents to select
any element.
Examples:
iex> "<div id=\"foo\"><div id=\"bar\">hi</div></div>" |> Exquery.tree |> Exquery.Query.all({:tag, "div", []})
[
{{:tag, "div", [{"id", "foo"}]}, [
{{:tag, "div", [{"id", "bar"}]}, [
{:text, "hi", []}
]}
]},
{{:tag, "div", [{"id", "bar"}]}, [
{:text, "hi", []}
]}
]
iex> "<div id=\"foo\"><div id=\"bar\">hi</div></div>" |> Exquery.tree |> Exquery.Query.all({:tag, "div", [{"id", "bar"}]})
[{{:tag, "div", [{"id", "bar"}]}, [{:text, "hi", []}]}]
iex> "<div id=\"foo\"><div id=\"bar\">hi</div></div>" |> Exquery.tree |> Exquery.Query.all({:tag, "div", [{"id", "nope"}]})
[]
Find the element before the specified element
A tree is an HTML tree given from Exquery.tree/1
A spec is an HTML elemement, which a three element tuple
of the element type, contents, and attributes.
<div id="foo"></div>
would look like {:tag, "div", [{"id", "foo"}]}
You may pass :any
in for the element type and element contents to select
any element.
An optional 3rd argument specifies the offset of the selected element. By default
it is 1, but you may select an element n
elements before to the specified element
by passing an offset of n
.
Examples:
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.before({:tag, "div", [{"id", "foo"}]})
nil
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.before({:tag, "div", [{"id", "bar"}]})
{{:tag, "div", [{"id", "foo"}]}, []}
iex> "<div id=\"foo\"></div><div id=\"bar\"></div><div id=\"baz\"></div>" |> Exquery.tree |> Exquery.Query.before({:tag, "div", [{"id", "baz"}]}, 2)
{{:tag, "div", [{"id", "foo"}]}, []}
Find the element by css id or class. More complex selections are a wip.
Examples:
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.css("#bar")
[{{:tag, "div", [{"id", "bar"}]}, []}]
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.css("#baz")
[]
iex> "<div id=\"foo\"></div><div id=\"bar\"></div><div class=\"baz\"></div>" |> Exquery.tree |> Exquery.Query.css(".baz")
[{{:tag, "div", [{"class", "baz"}]}, []}]
Find the element after the specified element
A tree is an HTML tree given from Exquery.tree/1
A spec is an HTML elemement, which a three element tuple
of the element type, contents, and attributes.
<div id="foo"></div>
would look like {:tag, "div", [{"id", "foo"}]}
You may pass :any
in for the element type and element contents to select
any element.
An optional 3rd argument specifies the offset of the selected element. By default
it is 1, but you may select an element n
elements next to the specified element
by passing an offset of n
.
Examples:
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.next({:tag, "div", [{"id", "foo"}]})
{{:tag, "div", [{"id", "bar"}]}, []}
iex> "<div id=\"foo\"></div><div id=\"bar\"></div>" |> Exquery.tree |> Exquery.Query.next({:tag, "div", [{"id", "bar"}]})
nil
iex> "<div id=\"foo\"></div><div id=\"bar\"></div><div id=\"baz\"></div>" |> Exquery.tree |> Exquery.Query.next({:tag, "div", [{"id", "foo"}]}, 2)
{{:tag, "div", [{"id", "baz"}]}, []}
Find the first element in the tree that matches the spec.
A tree is an HTML tree given from Exquery.tree/1
A spec is an HTML elemement, which a three element tuple
of the element type, contents, and attributes.
<div id="foo"></div>
would look like {:tag, "div", [{"id", "foo"}]}
You may pass :any
in for the element type and element contents to select
any element.
Examples:
iex> "<div id=\"foo\"><a id=\"bar\">hi</a></div>" |> Exquery.tree |> Exquery.Query.one({:tag, "a", [{"id", "bar"}]})
{{:tag, "a", [{"id", "bar"}]}, [{:text, "hi", []}]}
iex> "<div id=\"foo\"><a id=\"bar\">hi</a></div>" |> Exquery.tree |> Exquery.Query.one({:tag, "a", []})
{{:tag, "a", [{"id", "bar"}]}, [{:text, "hi", []}]}
iex> "<div id=\"foo\"><a id=\"bar\">hi</a></div>" |> Exquery.tree |> Exquery.Query.one({:tag, :any, [{"id", "bar"}]})
{{:tag, "a", [{"id", "bar"}]}, [{:text, "hi", []}]}
iex> "<div id=\"foo\"><a id=\"bar\">hi</a></div>" |> Exquery.tree |> Exquery.Query.one({:any, :any, [{"id", "bar"}]})
{{:tag, "a", [{"id", "bar"}]}, [{:text, "hi", []}]}
iex> "<div id=\"foo\"><a id=\"bar\">hi</a></div>" |> Exquery.tree |> Exquery.Query.one({:any, :any, [{"id", "does-not-exist"}]})
nil