Get combined text of all elements

84 Views Asked by At

Snippet of my attempt (using HXT and HandsomeSoup):

#!/usr/bin/env runhaskell

import           Text.HandsomeSoup
import           Text.XML.HXT.Core

main = do
  let html = "<html><body><a href='a'>b</a><a href='x'>y<p>z</p></a></body></html>"
  let doc = parseHtml html
  val <- runX $ doc >>> css "a" >>> deepest getText
  print val

Output:

["b","y","z"]

Desired output:

["b","yz"]

Essentially I am looking for a similar function like text() from jQuery.

Edit2: In jQuery it's literally a one-liner:

const texts = $('a').map((id, e) => $(e).text()).get();
0

There are 0 best solutions below