Created
July 19, 2011 04:38
-
-
Save kingcons/1091320 to your computer and use it in GitHub Desktop.
A toy for burke...
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
;; Adapted from https://github.com/swannodette/enlive-tutorial | |
;; Install clojure and leiningen, clone the above repo, do lein deps, then lein repl. | |
;; At that point, you just have to (load "tutorial/scrape1") then (in-ns 'tutorial.scrape1) | |
;; then (find-mp3s "http://www.aerialnoise.com/") and you're done. | |
(ns tutorial.scrape1 | |
(:require [net.cgrand.enlive-html :as html]) | |
(:require [clojure.contrib.str-utils2 :as str])) | |
(defn fetch-url [url] | |
(html/html-resource (java.net.URL. url))) | |
(defn extract-links [url] | |
(map #((%1 :attrs) :href) | |
(html/select (fetch-url url) [[:a (html/attr? :href)]]))) | |
(defn mp3-link? [url] | |
(= (str/tail url 4) ".mp3")) | |
(defn find-mp3s [url] | |
(filter mp3-link? (extract-links url))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment