Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
:dependencies [[org.clojure/clojure "1.5.1"]
[enlive "1.1.1"]
[ring "1.2.0"]
[clj-http "1.0.0"]
[net.cgrand/moustache "1.1.0"]])
5 changes: 3 additions & 2 deletions src/tutorial/scrape1.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns tutorial.scrape1
(:require [net.cgrand.enlive-html :as html]))
(:require [clj-http.client]
[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)))
(-> url clj-http.client/get :body java.io.StringReader. html/html-resource))

(defn hn-headlines []
(map html/text (html/select (fetch-url *base-url*) [:td.title :a])))
Expand Down
5 changes: 3 additions & 2 deletions src/tutorial/scrape2.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns tutorial.scrape2
(:require [net.cgrand.enlive-html :as html]))
(:require [clj-http.client]
[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)))
(-> url clj-http.client/get :body java.io.StringReader. html/html-resource))

(defn hn-headlines-and-points []
(map html/text
Expand Down