This is an area where I still feel I’m missing something essential in Clojure: a concise and idiomatic way to query a HTML document. Testing and any kind of scraping come to mind as use cases.
The main thing I need is quickly selecting elements based on CSS and/or Xpath.
(require '[imaginary-html-lib :as foo])
(def doc (foo/parse "<div class='hello'>Hello, <em>world<em></div>"))
(foo/select-css doc ".hello em") ;;=> #HTML[<em>world</em>]
(foo/text *1) ;;=> "world"
Sparkeldriver can do this, but if you already have HTML from some other source than maybe it’s not the most elegant solution.
There’s Hickory, which has it’s own “css style selectors”, but I already know CSS selectors, I don’t want to learn another DSL.
I guess Enlive comes closest to what I’m looking for, it uses clojure vectors as selectors, similar to how Garden does it, which I’m ok with. It could stand to be better documented though.
I don’t care too much about internal representation, although really it should be either clojure.xml style, or Hiccup