module Parser.LeboncoinParser ( 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 = catMaybes . fmap parseAd . partitions (~== (T.unpack "
  • ")) . parseTags parseAd :: [Tag Text] -> Maybe Ad parseAd tags = do name <- getTagTextAfter "" tags location <- getTagTextAfter "

    " tags let price = case getTagsBetween "" "" tags of [] -> Nothing xs -> Just $ innerText xs url <- getTagAttribute "" "href" tags return (Ad name location price (T.concat ["https://www.leboncoin.fr", url]))