Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (43 sloc) 1.93 KB


A library that makes easy the manipulation of HTML documents. This library is a wrapper around the JSoup Java library.

One example: retrieving the title of all the news in Hacker news:

($ "" td.title a (map #(text %1)))


  • Retrieval and parsing

      ($ "")
  • Selecting DOM elements (all the available JSoup selectors can be found here:

      ; equivalent
      ($ "" (search "tr")  (search "a"))
      ($ "" "tr" "a")
      ($ "" tr a)
      ; equivalent
      ($ "" (search "#footer"))
      ($ "" "#footer")
      ($ "" :footer)
  • Mixing any function in the chain of selectors

      ($ "" td a
         (filter (fn [e] (.startsWith (attr "href" e) "http")))
         (map (fn [e] {(attr "href" e) (text e)})))
      ;; returns a map with uri -> title
  • Manipulating the wrapped set adding elements from the same document or a different document

      ($ "<ul><li>item 1</li><li>item 2</li></ul><p>a paragraph</p>" li (add ($ "<a>hey</a>" a)) (add p) (text))
      ; gets " item 1 item 2 hey a paragraph"
  • Transforming an element into a set of S-Expressions

      ($ "<div><div class='test other'>hola</div><ul><li>uno</li><li id='two'>dos</li></ul></div>" div (s-expressions))
      ; outputs
      ([:div {}
        [[:divother.test {:class "test other"} "hola"]
         [:ul {}
           [[:li {} "uno"]
            [:li#two {:id "two"} "dos"]]]]]
       [:div.other.test {:class "test other"} "hola"])


leiningen and clojars:

[apricot-soup "0.0.3-SNAPSHOT"]


Copyright (C) 2010 Antonio Garrote

Distributed under the LGPL license.