Skip to content

zweifisch/enlive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

query html document with css selectors in elisp

Resources

Stars

Watchers

Forks

Packages

No packages published