아래는 koscom 에서 kospi200 시세를 얻어오는 예제이다. showindex
(ns showindexCLJ.core (:gen-class)) (set! *warn-on-reflection* true) (defn read-url "Return the web page as a string." [address] (let [url (java.net.URL. address)] (with-open [stream (. url openStream)] (def buf (java.io.BufferedReader. (java.io.InputStreamReader. stream))) (apply str (line-seq buf))))) (defn get-quote [] (def text (read-url "http://kosdb.koscom.co.kr/main/jisuticker.html")) (re-find #"KOSPI200.*</font>" text)) (defn -main [] (loop [] (let [now (java.util.Calendar/getInstance)] (println (str (java.util.Date.))) (println (get-quote)) (Thread/sleep (* 60 1000)) (loop [] (let [hour (. now get java.util.Calendar/HOUR)] (when (or (< hour 9) (> hour 14)) (Thread/sleep (* 60 1000)) (recur))))) (recur)))
slurp 사용:
(ns showindexCLJ.core)
(set! *warn-on-reflection* true)
(defn get-quote []
(def text (slurp "http://kosdb.koscom.co.kr/main/jisuticker.html"))
(re-find #"KOSPI200.*</font>" text))
(defn -main []
(loop []
(let [now (java.util.Calendar/getInstance)]
(println (str (java.util.Date.)))
(println (get-quote))
(Thread/sleep (* 60 1000))
(loop []
(let [hour (. now get java.util.Calendar/HOUR)]
(when (or (< hour 9) (> hour 14))
(Thread/sleep (* 60 1000)) (recur)))))
(recur)))
showindexCLJ-0.1.1-SNAPSHOT-standalone.jar
실행: java -jar JAR_FILE
See also
http://steloflute.tistory.com/search/web%20page
'My Computer Programs' 카테고리의 다른 글
DrClojure (0) | 2012.12.23 |
---|---|
(Java) get web page, KOSPI200 시세 얻기 (0) | 2012.12.11 |
cppcalc (0) | 2012.12.09 |
Tg - Esolang (0) | 2012.11.11 |
(C#) primes (0) | 2012.11.07 |