Skip to content

Latest commit

 

History

History
77 lines (51 loc) · 1.37 KB

README.md

File metadata and controls

77 lines (51 loc) · 1.37 KB

falcon

Build Status

Easy CSS-style selectors for HTML using JSoup.

Installation

Add to dependencies in project.clj:

[falcon "0.1.0"]

Usage

1. Parse

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>"))
2. Select

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.

3. Use

The result is a simplified Clojure data structure.

({:text "Stuff"
  :html "<b>Stuff</b>"
  :attrs {:class "hi"
          :data-x "1"}
  :children ({:text "Stuff"
              ...}))

Example

repl> (falcon/select
       (falcon/parse "https://reddit.com/r/clojure")
       "h1.redditname a")

({:text "Clojure"
     ...})

License

Copyright © 2015 Thomas Meier

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.