diff --git a/project.clj b/project.clj index a8495d2..c40a258 100644 --- a/project.clj +++ b/project.clj @@ -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"]]) diff --git a/src/tutorial/scrape1.clj b/src/tutorial/scrape1.clj index c13f8d7..39018ef 100644 --- a/src/tutorial/scrape1.clj +++ b/src/tutorial/scrape1.clj @@ -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]))) diff --git a/src/tutorial/scrape2.clj b/src/tutorial/scrape2.clj index 6f0f726..40ecb21 100644 --- a/src/tutorial/scrape2.clj +++ b/src/tutorial/scrape2.clj @@ -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