aboutsummaryrefslogtreecommitdiff
path: root/src/lib/haskell/Parser/SeLogerParser.hs
blob: b0738628001cef14b9906940e4022ad3b4c8ed4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Parser.SeLogerParser
  ( parse
  ) where

import           Data.Maybe        (catMaybes)
import           Data.Text         (Text)
import qualified Data.Text         as T
import           Text.HTML.TagSoup

import           Model.Ad          (Ad (Ad))
import           Parser.Utils

parse :: Text -> [Ad]
parse page =
  catMaybes . fmap parseAd $ partitions (~== (T.unpack "<div class=c-pa-info>")) tags
  where tags = getTagsBetween "<section class=liste_resultat>" "<div class=bottomAnchorWrapper>" (parseTags page)

parseAd :: [Tag Text] -> Maybe Ad
parseAd tags = do
  name <- getTagTextAfter "<a>" tags
  location <- getTagTextAfter "<div class=c-pa-city>" tags
  let price = getTagTextAfter "<span class=c-pa-cprice>" tags
  url <- getTagAttribute "<a>" "href" tags
  return (Ad name location price url)