【发布时间】:2013-01-12 14:20:11
【问题描述】:
我有以下问题。我正在为学校作业做 WebCrawler,我正在 Clojure 中做。这是代码。
(defn crawl [url current-depth max-depth]
(def hrefs (get-links url))
(if (< current-depth max-depth)
(map crawl hrefs (iterate eval (inc current-depth)) (iterate eval max-depth))
hrefs))
(defn get-links [page]
($ (get! page) td "a[href]" (attr "abs:href")))
get! 和 $ 函数不是我写的,我是从这里拿的:https://github.com/mfornos/clojure-soup/blob/master/src/jsoup/soup.clj
我的问题是,当我从 repl 调用 (crawl "http://bard.bg" 0 0) 时,我得到以下输出:
("http://www.bard.bg/genres/?id=1" "http://www.bard.bg/genres/?id=2" "http://www.bard.bg/genres/?id=4" "http://www.bard.bg/genres/?id=5" "http:/
("http://www.bard.bg/genres/?id=1" "http://www.bard.bg/genres/?id=2" "http://www.bard.bg/genres/?id=4" "http://www.bard.bg/genres/?id=5" "http:/
("http://www.bard.bg/genres/?id=1" "http://www.bard.bg/genres/?id=2" "http://www.bard.bg/genres/?id=4" "http://www.bard.bg/genres/?id=5" "http://www.bard.bg/genres/?id=6" "http://www.bard.bg/genres/?id=10" "http://www.bard.bg/genres/?id=17" "http://www.bard.bg/genres/?id=24"
...
那么第一个2lazyseqs 是从哪里来的呢?为什么他们未完成?
似乎问题出在 Clojure-Soup 中,更具体地说是:
(defmacro $ [doc & forms]
(let [exprs# (map #(if (string? %) `(select ~%)
(if (symbol? %) `(select ~(str %))
(if (keyword? %) `(select ~(str "#"(name %)))
%))) forms)]
`(->> ~doc ~@exprs#)))`
【问题讨论】:
-
请分享您所引用的库和版本的链接。
-
github.com/mfornos/clojure-soup 这是我从中获得的回购协议。
标签: html recursion web clojure output