Database Reference
In-Depth Information
How to do it…
1.
Since this task is a little complicated, let's pull out the steps into several functions:
(defn to-keyword
"This takes a string and returns a normalized keyword."
[input]
(->input
string/lower-case
(string/replace \space \-)
keyword))
(defn load-data
"This loads the data from a table at a URL."
[url]
(let [page (html/html-resource (URL. url))
table (html/select page [:table#data])
headers (->>
(html/select table [:tr :th])
(map html/text)
(map to-keyword)
vec)
rows (->> (html/select table [:tr])
(map #(html/select % [:td]))
(map #(map html/text %))
(filterseq))]
(i/dataset headers rows))))))
2.
Now, call load-data with the URL you want to load data from:
user=> (load-data (str "http://www.ericrochester.com/"
"clj-data-analysis/data/small-sample-table.html"))
| :given-name | :surname | :relation |
|-------------+----------+-------------|
| Gomez | Addams | father |
| Morticia | Addams | mother |
| Pugsley | Addams | brother |
| Wednesday | Addams | sister |
 
Search WWH ::




Custom Search