Last active
December 19, 2015 11:29
-
-
Save jackrusher/5947710 to your computer and use it in GitHub Desktop.
Fetch a page, following any redirects on the way, return the page as an Enlive resource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; follows redirects | |
(defn fetch-page [url] | |
(enlive/html-resource | |
(loop [final-url (java.net.URL. url)] | |
(let [conn (.openConnection final-url)] | |
(if (re-find #"30[1-3]" (.getHeaderField conn 0)) | |
(recur (java.net.URL. (.getHeaderField conn "location"))) | |
final-url))))) | |
;; grab page title string | |
(first (enlive/select (fetch-page "http://google.com") [:title enlive/text])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment