Created
April 5, 2013 07:02
-
-
Save antonvolkoff/5317206 to your computer and use it in GitHub Desktop.
Prints href attributes from given page.
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
(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