Decode a part of a website

Hi everyone. I am very new to elixir but finding it amazing. Here is what I am trying to do. I am trying to decode a certain part of a website that contains aviation forecast (Called TAF). In my mix.exs I have added the tesla and poison deps. I am using the steps from this site (Writing your first Elixir package (Part 2) | by Syed Faraaz Ahmad | The Wheel | Medium).

The aviation weather site is (METAR Reader - Your preflight weather companion). FACT is the code for Cape Town. If you inspect the code (I am using google), you will find: section class=β€œreport” . That will show you the weather forecase.

What I have done (Working in iex) is:

  1. response = Tesla.get(β€œMETAR Reader - Your preflight weather companion”) All OK so far
  2. response = response.body. All OK so far
  3. {:ok, result} = Poison.decode response . This is where I get the following error:

** (MatchError) no match of right hand side value: {:error, {:invalid, β€œ<”, 0}}

The way I see it is that I am trying to decode the entire body and there are many HTML tags which I understand. What I am trying to do as mentioned, is just get that part of the site that shows the forecast.

Kind regards
Dmitri

Hello,

You need Floki or similar to parse html.

Poison is for json, and there is now Jason instead.

Happy Elixir learning :slight_smile:

2 Likes

Thanks you. Will look at Floki