Skip to content

Instantly share code, notes, and snippets.

@zcaudate
Created June 29, 2012 22:03
Show Gist options
  • Save zcaudate/3020922 to your computer and use it in GitHub Desktop.
Save zcaudate/3020922 to your computer and use it in GitHub Desktop.
html->hiccup
(use 'net.cgrand.enlive-html)
(import 'java.io.StringReader)
(defn enlive->hiccup
[el]
(if-not (string? el)
(->> (map enlive->hiccup (:content el))
(concat [(:tag el) (:attrs el)])
(keep identity)
vec)
el))
(defn html->enlive
[html]
(first (html-resource (StringReader. html))))
(defn html->hiccup [html]
(-> html
html->enlive
enlive->hiccup))
(html->hiccup "<body>Hello There</body>")
;; => [:html [:body "Hello There"]]
(require '[clj-http.client :as cl])
(-> (cl/get "http://www.google.com") :body html->hiccup)
;; => A BUNCH OF GOOGLE TEXT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment