Easy CSS-style selectors for HTML using JSoup.
Add to dependencies in project.clj
:
[falcon "0.1.0"]
First, you need some HTML parsed.
(ns (:require [falcon.core :as falcon]))
(def parsed-html (falcon/parse "http://google.com"))
Or, if you have a string of HTML,
(def parsed-html
(falcon/parse-string
"<div><p class='hi' data-x="1"><b>Stuff</b></p></div>"))
Then select using the parsed HTML and a CSS-style selector.
(def elements
(first
(falcon/select parsed-html ".hi")))
Check out all the possible selectors at JSoup Selector Syntax.
The result is a simplified Clojure data structure.
({:text "Stuff"
:html "<b>Stuff</b>"
:attrs {:class "hi"
:data-x "1"}
:children ({:text "Stuff"
...}))
repl> (falcon/select
(falcon/parse "https://reddit.com/r/clojure")
"h1.redditname a")
({:text "Clojure"
...})
Copyright © 2015 Thomas Meier
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.