这是一个使用 Enlive的解析示例。与Enliven有区别吗?
(ns parse.enlive
(:require [net.cgrand.enlive-html :as html]))
(def ^:dynamic *base-url* "https://news.ycombinator.com/")
(defn fetch-url [url]
(html/html-resource (java.net.URL. url)))
(defn hn-headlines []
(map html/text (html/select (fetch-url *base-url*) [:td.title :a])))
(defn hn-points []
(map html/text (html/select (fetch-url *base-url*) [:td.subtext html/first-child])))
(defn print-headlines-and-points []
(doseq [line (map #(str %1 " (" %2 ")") (hn-headlines) (hn-points))]
(println line)))
如果在这个简单的例子中没有太大的区别,那么在进行一些网络抓取时,Enliven 会有什么不同呢?
谢谢!