Last active
May 19, 2021 23:36
-
-
Save zk/23c7c666289244064c2bc9b47eaf0fa5 to your computer and use it in GitHub Desktop.
Clojuredocs scraper
This file contains 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
(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