Add extractor for finertech.com
This commit is contained in:
parent
118de4ae53
commit
8c96a94cd3
|
@ -0,0 +1,39 @@
|
|||
defmodule Frenzy.Pipeline.Extractor.FinerTech do
|
||||
@moduledoc """
|
||||
Extractor for https://finertech.com
|
||||
"""
|
||||
|
||||
alias Frenzy.Pipeline.Extractor
|
||||
@behaviour Extractor
|
||||
|
||||
@impl Extractor
|
||||
def extract(html_tree) do
|
||||
case Floki.find(html_tree, ".entry-content") do
|
||||
[content_elem | _] ->
|
||||
# remove patreon button
|
||||
content_elem = Floki.traverse_and_update(content_elem, &remove_patreon_banner/1)
|
||||
{:ok, content_elem}
|
||||
|
||||
_ ->
|
||||
{:error, "no matching element"}
|
||||
end
|
||||
end
|
||||
|
||||
@patreon_class_regex ~r/[a-z0-9_]patreon_button/i
|
||||
|
||||
defp remove_patreon_banner({"div", attrs, _children} = elem) do
|
||||
case Enum.find(attrs, fn {attr, _val} -> attr == "class" end) do
|
||||
nil ->
|
||||
elem
|
||||
|
||||
{"class", class} ->
|
||||
if Regex.match?(@patreon_class_regex, class) do
|
||||
nil
|
||||
else
|
||||
elem
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp remove_patreon_banner(elem), do: elem
|
||||
end
|
Loading…
Reference in New Issue