Skip to content

Instantly share code, notes, and snippets.

@zk
Last active May 19, 2021 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zk/23c7c666289244064c2bc9b47eaf0fa5 to your computer and use it in GitHub Desktop.
Save zk/23c7c666289244064c2bc9b47eaf0fa5 to your computer and use it in GitHub Desktop.
Clojuredocs scraper
(require '[clojure.string :as str])
(require '[clojure.edn :as edn])
(defn fetch-page-data [clojuredocs-url]
(let [ ; get the window.PAGE_DATA=... line from var page HTML source
page-data-str (-> (slurp clojuredocs-url)
(str/split #"\n")
(nth 2) ; get the 3rd line of the HTML source
)]
(->> page-data-str
(drop (count "window.PAGE_DATA=")) ; Drop leading characters
butlast ; Drop trailing semicolon
(apply str)
edn/read-string
edn/read-string ; Double decode (not a mistake)
)))
(fetch-page-data "https://clojuredocs.org/clojure.core/map")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment