aboutsummaryrefslogtreecommitdiff
path: root/src/Parser/Utils.hs
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-11 20:38:08 +0200
committerJoris Guyonvarch2015-04-11 20:38:08 +0200
commitaafc45eb5eed3839a5210a7d48928d975df6a296 (patch)
tree8574205bdf967b7338e63bc77c2f1374e0843e67 /src/Parser/Utils.hs
parent4ddd6d1f6df2bab75d42b6d45b816e92e7173529 (diff)
downloadad-listener-aafc45eb5eed3839a5210a7d48928d975df6a296.tar.gz
ad-listener-aafc45eb5eed3839a5210a7d48928d975df6a296.tar.bz2
ad-listener-aafc45eb5eed3839a5210a7d48928d975df6a296.zip
Handle a configuration file to save the url
Diffstat (limited to 'src/Parser/Utils.hs')
-rw-r--r--src/Parser/Utils.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/Parser/Utils.hs b/src/Parser/Utils.hs
index 8527777..16fe3d2 100644
--- a/src/Parser/Utils.hs
+++ b/src/Parser/Utils.hs
@@ -6,27 +6,28 @@ module Parser.Utils
import Data.List (find, findIndex)
import Data.Maybe (listToMaybe)
+import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup
-getTagsBetween :: String -> String -> [Tag T.Text] -> [Tag T.Text]
+getTagsBetween :: String -> String -> [Tag Text] -> [Tag Text]
getTagsBetween beginSelector endSelector =
takeWhile (~/= endSelector)
. drop 1
. dropWhile (~/= beginSelector)
-getTagAttribute :: String -> T.Text -> [Tag T.Text] -> Maybe T.Text
+getTagAttribute :: String -> Text -> [Tag Text] -> Maybe Text
getTagAttribute selector attribute tags =
find (~== selector) tags >>= maybeTagAttribute attribute
-getTagTextAfter :: String -> [Tag T.Text] -> Maybe T.Text
+getTagTextAfter :: String -> [Tag Text] -> Maybe Text
getTagTextAfter selector tags =
case findIndex (~== selector) tags of
Just index -> fmap T.strip $ safeGetAt (index + 1) tags >>= maybeTagText
Nothing -> Nothing
-maybeTagAttribute :: T.Text -> Tag T.Text -> Maybe T.Text
+maybeTagAttribute :: Text -> Tag Text -> Maybe Text
maybeTagAttribute name (TagOpen _ xs) =
fmap snd . find (\(x, _) -> x == name) $ xs
maybeTagAttribute attribute _ = Nothing