Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Nokogiri for Clojure
Clojure
tree: f06871a326

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
docs
src/yokogiri
test/yokogiri/test
.gitignore
.travis.yml
CHANGELOG.org
README.markdown
TODO.org
project.clj

README.markdown

yokogiri

status

Build Status

getting started

In your project.clj: [yokogiri "1.5.6"]

  (ns myproject.core
    (:require [yokogiri.core :as yokogiri]))

or

  (ns myproject.core
    (:use [yokogiri.core]))

usage

  (def client (make-client))

  ;; with javascript enabled (look at the docstring for make-client
  ;; for all of the available options.):
  (def client (make-client :javascript false))

  ;; Curious what options are set by default?
  (get-client-options (make-client))
  ;=> {:redirects true, :javascript true, ...}

  ;; XPATH
  ;; First, we get the *page*.
  (def page (get-page client "http://example.com"))

  (xpath page "//a")
  ;=> [#<HtmlAnchor HtmlAnchor[<a href="http://www.iana.org/domains/example">]>]

  (map attrs (xpath page "//a"))
  ;=> ({:text "More information...", :href "http://www.iana.org/domains/example"})

  (map node-text (xpath page "//a"))
  ;=> ("More information...")

  ;; CSS
  (def footer-feedback-text
    (map node-text (css page "div.footer-beta-feedback")))

  ;; Get specific attributes
  (def a-attr-href
    (map #(select-keys (attrs %) [:href])
      (-> page (css "div.link a"))))

license

Copyright (C) 2013 Devin Walters

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.