All Projects → zweifisch → enlive

zweifisch / enlive

Licence: other
query html document with css selectors in elisp

Programming Languages

emacs lisp
2029 projects
shell
77523 projects

enlive

https://travis-ci.org/zweifisch/enlive.svg?branch=master http://stable.melpa.org/packages/enlive-badge.svg

query html document with css selectors

supported selectors

selectordescription
:id [:main]
.class [.content.home-page]
tagtagname [p.demo a]
>direct children [.article > p]
*all nodes [:section > *]
  • use : for id not #
  • leave spaces around >, like [:app.items > .item > a]

usage

enlive-fetch

#+BEGIN_SRC elisp
(require 'enlive)

(enlive-text
 (enlive-query (enlive-fetch "http://gnu.org/") [title]))
#+END_SRC

#+RESULTS:
: The GNU Operating System and the Free Software Movement

enlive-parse

#+BEGIN_SRC elisp :results raw
(enlive-query-all
 (enlive-parse "<div class=\"content\">
                   <p>p1</p>
                   <p>p2</p>
                </div>")
 [.content p])
#+END_SRC

#+RESULTS:
((p nil p1) (p nil p2))

enlive-query

  • enlive-query-all will return all node mached

enlive-with

#+BEGIN_SRC elisp :results raw
(macroexpand '(enlive-with element
                           (enlive-query [div])
                           (enlive-query-all [.cls])))
#+END_SRC

#+RESULTS:
(progn (enlive-query element [div]) (enlive-query-all element [.cls]))

enlive-let

#+BEGIN_SRC elisp :results raw
(enlive-let (enlive-parse "<span><i class=\"foo\">foo</i><i class=\"bar\">bar</i></span>")
            ((foo [.foo])
             (bar [.bar]))
            (list (enlive-text (car foo)) (enlive-text (car bar))))
#+END_SRC

#+RESULTS:
(foo bar)

some dom related functions

  • enlive-get-element-by-id
  • enlive-get-elements-by-tag-name
  • enlive-get-elements-by-class-name
  • enlive-has-class
  • enlive-attr
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].