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)

Level up your Elixir skills

Request a free email course

Back to index

3 Comments

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

Nice one again ! Thanks !

- jtoulouse · 4 years ago