From 5eb4b914899a44b795ab2df865781f08f6f64e2c Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 27 Jun 2021 10:08:28 +1200 Subject: [PATCH] Add search by tag name to JSON interface. (Search by CSS selector seems close enough in the HTML interface that this wouldn't be useful. --- src/Internal/Elements.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Internal/Elements.hs b/src/Internal/Elements.hs index f82bc87..045a94d 100644 --- a/src/Internal/Elements.hs +++ b/src/Internal/Elements.hs @@ -18,6 +18,7 @@ import qualified XML.Selectors.CSS as CSS import Network.URI (parseURIReference) import Data.Maybe +import Data.String (fromString) getTitle :: Session -> IO Text getTitle session = getTitle' <$> documentRoot <$> document <$> readMVar session @@ -44,6 +45,7 @@ find (Find "css selector" sel) root = case CSS.parsePath sel of Left msg -> Left (True, msg) find (Find "link text" sel) root = Right $ allLinks (== pack sel) root find (Find "partial link text" sel) root = Right $ allLinks (Txt.isInfixOf $ pack sel) root +find (Find "tag name" sel) root = Right (X.descendant root >>= X.checkName (== fromString sel)) find (Find type_ _) _ = Left (False, "Invalid selector type: " ++ Txt.unpack type_) allLinks test = X.descendant X.>=> -- 2.30.2