Skip to content

Clojure wrapper around JSoup for CSS Selectors

Notifications You must be signed in to change notification settings

ThomasMeier/falcon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Clojure wrapper around JSoup for CSS Selectors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published