Created
June 29, 2012 22:03
-
-
Save zcaudate/3020922 to your computer and use it in GitHub Desktop.
html->hiccup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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