← All series

Series contents

Log in to track your progress

  1. 1. A worker to log stats from a YouTube’s API Episode
  2. 2. Querying Alexa Site API and parsing XML Episode
  3. 3. Adding Ecto and a Postgres database to StatWatch Episode
  4. 4. Putting an Elixir OTP app in our Elixir OTP app Episode
  5. 5. Launching StatWatch.me (side project) Episode
  6. 6. Planning a Phoenix web app for StatWatch Episode
  7. 7. From backend OTP app to Phoenix app Episode
  8. 8. Adding sessions and logins to StatWatch Episode
  9. 9. Password hashing and Ecto associations for StatWatch Episode
  10. 10. Permalinks and an admin auth plug for StatWatch Episode
  11. 11. Creating Ecto associations between profiles and stats Episode
  12. 12. Zero Dependency Pagination in Phoenix (Part 1) Episode
  13. 13. Zero Dependency Pagination in Phoenix (Part 2) Episode

Querying Alexa Site API and parsing XML

We extend the StatWatch worker we just built to regularly pull in data from Alexa site rankings and log it along with the data it was already getting from the YouTube Data API.

Since the site ranking data is given in XML, we'll add SweetXml to our mix project for parsing.

(Source code available for premium members)

Open standalone page ↗

3 Comments

Nice one again ! Thanks !

- jtoulouse · 4 years ago

Very useful to see how to handle XML responses. Looks like Alexa are no longer serving stats responses to the URL used in the example though.

- lurnid · 6 years ago

Here's the code that's running in production right now:

def fetch_alexa(profile) do
  if profile.url do
    %{body: body} = HTTPoison.get!("data.alexa.com/data?cli=10&url=#{profile.url}")
    body |> xpath(~x"//POPULARITY/@TEXT"s) || "unranked"
  end
end

You can see it here: https://statwatch.me/profiles/alchemist

- alchemist · 6 years ago