From e0f75fe5b80092242e5657be464843f14574f947 Mon Sep 17 00:00:00 2001 From: artlef Date: Tue, 1 May 2018 15:13:49 +0200 Subject: [PATCH] Add simple parse html --- Main.hs | 3 ++- ParseHtml.hs | 17 +++++++++++++++++ makefile | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 ParseHtml.hs diff --git a/Main.hs b/Main.hs index e60297d..31671fc 100644 --- a/Main.hs +++ b/Main.hs @@ -2,9 +2,10 @@ module Main where import System.Environment import Download +import ParseHtml main :: IO () main = do args <- getArgs htmlResult <- downloadHtmlDef (head args) - putStrLn htmlResult + printDifferentDef htmlResult diff --git a/ParseHtml.hs b/ParseHtml.hs new file mode 100644 index 0000000..45b5235 --- /dev/null +++ b/ParseHtml.hs @@ -0,0 +1,17 @@ +module ParseHtml (printDifferentDef) where + +import Text.HTML.TagSoup + +printDifferentDef :: String -> IO () +printDifferentDef x = putStrLn (getDifferentDefMessages x) + +getDifferentDefMessages :: String -> String +getDifferentDefMessages x = renderTags (differentDefTags x) + +differentDefTags :: String -> [Tag String] +differentDefTags = + filter (~== TagText "") . (takeWhile (~/= "
")) + . (dropWhile (~/= "
")) . parseTags + +numberOfDef :: [Tag String] -> Int +numberOfDef tags = ((length tags) + 1) `div` 3 diff --git a/makefile b/makefile index f013db0..a1aca57 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ CC=ghc ARGS=--make -dynamic FILENAME=dictfr all: - $(CC) $(ARGS) -o $(FILENAME) Main.hs Download.hs + $(CC) $(ARGS) -o $(FILENAME) Main.hs Download.hs ParseHtml.hs clean: rm -f *.o *.hi