Skip to content

Instantly share code, notes, and snippets.

@antonvolkoff
Created April 5, 2013 07:02
Show Gist options
  • Save antonvolkoff/5317206 to your computer and use it in GitHub Desktop.
Save antonvolkoff/5317206 to your computer and use it in GitHub Desktop.
Prints href attributes from given page.
(ns zenbot.core
(:gen-class)
(:require [clj-http.client :as client])
(:require [net.cgrand.enlive-html :as html]))
(defn fetch-url-body
"Fetches given address and returns it's body."
[address]
(:body (client/get address)))
(defn attrs
"Destrucs map to get href attribute."
[coll]
(let [{href :href}
(let [{attrs :attrs} coll]
attrs)]
href))
(defn get-all-links
"Retuns back a vector of links."
[address]
(html/select (html/html-resource
(java.io.StringReader. (fetch-url-body address)))
[:a]))
(defn -main
"Prints all links from the given page."
[& args]
(doseq [line (map attrs (get-all-links "http://techcrunch.com"))]
(println line)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment