defmodule Elixpose do @moduledoc """ `Elixpose` helps you to scrap web pages. It shows you a lot of information about the page. """ @doc """ Count the CSS referenced ## Examples iex> Elixpose.count_css("https://pt.stackoverflow.com/") 3 """ def count_css(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("link[rel=stylesheet]") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Count the JS referenced ## Examples iex> Elixpose.count_js("https://pt.stackoverflow.com/") 19 """ def count_js(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("script") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Count the HTML Elements ## Examples iex> Elixpose.count_html_elements("https://pt.stackoverflow.com/") 1 """ def count_html_elements(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("html") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Count the HTML Elements ## Examples iex> Elixpose.count_meta_tags("https://pt.stackoverflow.com/") 12 """ def count_meta_tags(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("meta") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Count the OnClick events ## Examples iex> Elixpose.count_onclick_events("https://pt.stackoverflow.com/") 15 """ def count_onclick_events(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("body") |> Floki.find("[onclick]") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Count the amount of Forms in the HTML ## Examples iex> Elixpose.count_forms("https://pt.stackoverflow.com/") 1 """ def count_forms(url, headers \\ []) do case HTTPoison.get(url, headers) do {:ok, %{body: raw_body, status_code: code}} -> {code, raw_body} html = raw_body {:ok, document} = Floki.parse_document(html) document |> Floki.find("form") |> Enum.count() {:error, %{reason: reason}} -> {:error, reason} end end @doc """ Get the text content from