module Parser.OuestFranceParser ( 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 "")) tags where tags = getTagsBetween "
" "
" (parseTags page) parseAd :: [Tag Text] -> Maybe Ad parseAd tags = do name <- getTagTextAfter "" tags location <- getTagTextAfter "" tags let price = getTagTextAfter "" tags let startUrl = "https://www.ouestfrance-immo.com/" url <- getTagAttribute "" "href" tags return (Ad name location price (T.concat [startUrl, url]))