blob: 77213cbab56b2bbfb46e185929f645908f827415 (
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.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 page =
catMaybes . fmap parseAd $ partitions (~== (T.unpack "<a>")) tags
where tags = getTagsBetween "<li itemtype=http://schema.org/Offer>" "<div class=information-immo_content>" (parseTags page)
parseAd :: [Tag Text] -> Maybe Ad
parseAd tags = do
name <- getTagTextAfter "<h2 class=item_title>" tags
location <- getTagAttribute "<meta itemprop=address>" "content" tags
let price = getTagTextAfter "<h3 class=item_price>" tags
url <- getTagAttribute "<a>" "href" tags
return (Ad name location price (T.concat ["https:", url]))
|