Created
February 10, 2012 08:42
-
-
Save syou6162/1787841 to your computer and use it in GitHub Desktop.
はてなフォトライフから並行に画像をダウンロードしてくる例
This file contains hidden or 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
(use '[clojure.java.io :only (copy output-stream)]) | |
(def pic-url "http://blog.stackoverflow.com/wp-content/uploads/justice-league-small.jpg") | |
(defn input-stream [pic-url] | |
(-> pic-url java.net.URL. .openConnection .getInputStream)) | |
(defn get-byte-array-stream [input-stream] | |
(let [byte-array-stream (java.io.ByteArrayOutputStream.)] | |
(copy input-stream byte-array-stream) | |
(.toByteArray byte-array-stream))) | |
(defn save-pic [pic-url] | |
(let [filename (str "/Users/yasuhisa/" (second (re-find #".*\/(.+)$" pic-url)))] | |
(with-open [output (output-stream filename)] | |
(copy | |
(get-byte-array-stream (input-stream pic-url)) output)))) | |
(save-pic pic-url) | |
(def my-source (slurp* "http://f.hatena.ne.jp/syou6162")) | |
(pmap save-pic (map second (re-seq #"img.*?class=\"foto_thumb\" src=\"(.*?)\"" my-source))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment