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
- Host: GitHub
- URL: https://github.com/zweifisch/enlive
- Owner: zweifisch
- Created: 2015-07-03T12:46:27.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-30T10:02:05.000Z (about 3 years ago)
- Last Synced: 2025-01-27T22:55:08.781Z (over 1 year ago)
- Language: Emacs Lisp
- Size: 7.81 KB
- Stars: 45
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.org
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=