Skip to content

Instantly share code, notes, and snippets.

@kingcons
Created July 19, 2011 04:38
Show Gist options
  • Save kingcons/1091320 to your computer and use it in GitHub Desktop.
Save kingcons/1091320 to your computer and use it in GitHub Desktop.
A toy for burke...
;; 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