|
|
@@ -16,6 +16,8 @@ import LinkedIn.Utils as U
|
|
|
import Web.DOM (Node)
|
|
|
import Web.DOM.Node as N
|
|
|
import Web.DOM.NodeList as NL
|
|
|
+import Web.DOM.NodeType (NodeType(..))
|
|
|
+import Web.DOM.Text as T
|
|
|
|
|
|
data QueryError =
|
|
|
QNodeNotFoundError String
|
|
|
@@ -54,13 +56,17 @@ queryOne selector node = ExceptT $ do
|
|
|
maybeNode <- U.queryOne selector node
|
|
|
pure $ note (QNodeNotFoundError selector) maybeNode
|
|
|
|
|
|
-queryText ∷ QueryRunner Node
|
|
|
-queryText n = ExceptT $ do
|
|
|
+queryText ∷ Int -> QueryRunner Node
|
|
|
+queryText idx n = ExceptT $ do
|
|
|
children <- N.childNodes n
|
|
|
childrenArr <- NL.toArray children
|
|
|
+ let
|
|
|
+ maybeText n' = do
|
|
|
+ _ <- T.fromNode n'
|
|
|
+ pure $ n'
|
|
|
+ allTexts = A.mapMaybe maybeText childrenArr
|
|
|
|
|
|
- pure $ note QTextNotFoundError $ A.head childrenArr
|
|
|
+ pure $ note QTextNotFoundError $ A.index allTexts idx
|
|
|
|
|
|
queryAll ∷ String → QueryRunner (NonEmptyList Node)
|
|
|
queryAll selector node = ExceptT $ do
|