scraping
All checks were successful
Build and Deploy / Build & Push Image (push) Successful in 31s

This commit is contained in:
2026-03-16 21:08:00 -06:00
parent a4568d124a
commit c5ebf5b9af

View File

@@ -105,38 +105,34 @@ defmodule CobblemonUi.TierListScraper do
end end
defp parse(html) do defp parse(html) do
nodes = html |> Floki.parse_document!() |> Floki.find(".pokemon-tier") bands = html |> Floki.parse_document!() |> Floki.find(".tierlist-band")
Logger.debug("[TierListScraper] Found #{length(nodes)} .pokemon-tier nodes") Logger.debug("[TierListScraper] Found #{length(bands)} .tierlist-band nodes")
case nodes do case bands do
[] -> [] ->
Logger.warning("[TierListScraper] No .pokemon-tier elements found — page structure may have changed or content is JS-rendered") Logger.warning("[TierListScraper] No .tierlist-band elements found — page structure may have changed")
{:error, :no_pokemon_found} {:error, :no_pokemon_found}
_ -> _ ->
pokemon = Enum.map(nodes, &extract_pokemon/1) pokemon =
valid = Enum.filter(pokemon, fn %{name: n} -> n != "" end) Enum.flat_map(bands, fn band ->
Logger.info("[TierListScraper] Parsed #{length(valid)} valid pokemon (#{length(pokemon) - length(valid)} skipped with empty names)") tier = band |> Floki.attribute("data-tier") |> List.first() |> to_string() |> String.upcase()
{:ok, valid} cards = Floki.find(band, ".tierlist-card")
Enum.flat_map(cards, fn card ->
case card |> Floki.attribute("data-name") |> List.first() do
nil -> []
"" -> []
name -> [%{name: String.trim(name), tier: tier}]
end
end)
end)
Logger.info("[TierListScraper] Parsed #{length(pokemon)} pokemon across #{length(bands)} tiers")
{:ok, pokemon}
end end
end end
defp extract_pokemon(node) do
name =
node
|> Floki.find(".name")
|> Floki.text()
|> String.trim()
tier =
node
|> Floki.find(".tier")
|> Floki.text()
|> String.trim()
%{name: name, tier: tier}
end
defp write_json(data) do defp write_json(data) do
path = output_file() path = output_file()
Logger.debug("[TierListScraper] Writing cache to #{path}") Logger.debug("[TierListScraper] Writing cache to #{path}")