Javelin:
(import java.util)
(def interval 5)
(prn "Refreshes every" interval "minutes.")
;; compile-time regex
(defmacro regex (str)
(. java.util.regex.Pattern compile str))
(defn re-groups (re text g)
(def result (list))
(def m (. re matcher text))
(while (. m find) (. result add (. m group g)))
result)
(defn list-naver ()
(re-groups (regex "<option value=\".+\">.+: (.+)</option>") (slurp "http://www.naver.com") 1))
(defn list-daum ()
(new LinkedHashSet
(re-groups
(regex "<span class=\"txt_issue\">\n.+\n(<.+>)?(.+?)(<.+>)?\n") (slurp "http://www.daum.net") 2)))
(while true
(try
(prn (new Date))
(prn "Naver:" (list-naver))
(prn "Daum:" (list-daum))
(catch Exception e (prn e)))
(. Thread sleep (* 1000 60 interval))
(prn))
Clojure:
(import (java.util Date))
(def interval 5)
(println "Refreshes every" interval "minutes.")
(defn list-naver []
(map #(% 1) (re-seq #"<option value=\".+\">.+: (.+)</option>" (slurp "http://www.naver.com"))))
(defn list-daum []
(distinct (map #(% 2) (re-seq #"<span class=\"txt_issue\">\n.+\n(<.+>)?(.+?)(<.+>)?\n" (slurp "http://www.daum.net")))))
(while true
(try
(println (str (new Date)))
(println "Naver:" (clojure.string/join ", " (list-naver)))
(println "Daum:" (clojure.string/join ", " (list-daum)))
(catch Exception e (println e)))
(. Thread sleep (* 1000 60 interval))
(println))
'My Computer Programs' 카테고리의 다른 글
EURKRW ticker (0) | 2015.12.11 |
---|---|
CSI 300 ticker (0) | 2015.10.15 |
(C#) LineNumRemover (0) | 2015.08.16 |
(C#) naver-daum-top-search-scraper (0) | 2015.06.19 |
(Racket) naver-daum-top-search-scraper (0) | 2015.06.17 |