An open API service indexing awesome lists of open source software.

https://github.com/zweifisch/enlive

query html document with css selectors in elisp
https://github.com/zweifisch/enlive

Last synced: 6 months ago
JSON representation

query html document with css selectors in elisp

Awesome Lists containing this project

README

          

* enlive

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

query html document with css selectors

** supported selectors

| selector | description |
|----------+----------------------------------|
| =:= | id =[:main]= |
| =.= | class =[.content.home-page]= |
| =tag= | tagname =[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 "


:

p1


:

p2


:
")
: [.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 "foobar")
: ((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=