blob: f46ed03530159af60b53c6aec10ac38bc8ef2686 (
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
25
|
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 "<a>")) tags
where tags = getTagsBetween "<div id=listAnnonces>" "<div id=interactions>" (parseTags page)
parseAd :: [Tag Text] -> Maybe Ad
parseAd tags = do
name <- getTagTextAfter "<span class=annTitre>" tags
location <- getTagTextAfter "<span class=annVille>" tags
let price = getTagTextAfter "<span class=annPrix>" tags
let startUrl = "https://www.ouestfrance-immo.com/"
url <- getTagAttribute "<a>" "href" tags
return (Ad name location price (T.concat [startUrl, url]))
|