Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created February 22, 2010 05:16
Show Gist options
  • Save swannodette/310820 to your computer and use it in GitHub Desktop.
Save swannodette/310820 to your computer and use it in GitHub Desktop.
(ns littlesis.names
(:require [net.cgrand.enlive-html :as html]))
(def *base-url* "http://blog.littlesis.org/2010/02/18/sources-allege-goldman-sachs-and-john-paulson-are-partnering-in-speculative-attacks-o\
n-greece/")
(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
(defn entry [node]
(first (html/select node [:div.entry])))
;; could probably be better expressed as reduce
(defn text-nodes [node]
(let [content (:content node)]
(loop [subnode (first content) nodes (rest content) result []]
(if (nil? subnode)
result
(if (= (type subnode) java.lang.String)
(recur (first nodes) (rest nodes) (conj result subnode))
(recur (first nodes) (rest nodes) (into result (text-nodes subnode))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment