mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-27 12:44:22 +00:00
Samples
This commit is contained in:
parent
16fd925625
commit
125afe7acc
@ -3,7 +3,7 @@
|
|||||||
Parse HTML text into a tree of elements with selectors
|
Parse HTML text into a tree of elements with selectors
|
||||||
|
|
||||||
##License
|
##License
|
||||||
MIT; see ./doc/LICENSE
|
MIT; see `./doc/LICENSE`
|
||||||
|
|
||||||
##Usage
|
##Usage
|
||||||
Start off with
|
Start off with
|
||||||
@ -57,8 +57,13 @@ Selectors can be combined; e.g. `".class:not([attribute]) element.class"`
|
|||||||
- Attribute values in selectors currently cannot contain any spaces, since space is interpreted as a delimiter between the `ancestor` and `descendant`, `parent` and `>`, or `>` and `child` parts of the selector
|
- Attribute values in selectors currently cannot contain any spaces, since space is interpreted as a delimiter between the `ancestor` and `descendant`, `parent` and `>`, or `>` and `child` parts of the selector
|
||||||
- Likewise, for the `parent > child` relation, the spaces before and after the `>` are mandatory
|
- Likewise, for the `parent > child` relation, the spaces before and after the `>` are mandatory
|
||||||
|
|
||||||
|
##Examples
|
||||||
|
See `.doc/smples.lua`
|
||||||
|
|
||||||
##Element type
|
##Element type
|
||||||
All tree elements provide, apart from `:select` and `()`, the following accessors:
|
All tree elements provide, apart from `:select` and `()`, the following accessors:
|
||||||
|
|
||||||
|
###Basic
|
||||||
- `.name` = the element's tagname
|
- `.name` = the element's tagname
|
||||||
- `.attributes` = a table with keys and values for the element's attributes; `{}` if none
|
- `.attributes` = a table with keys and values for the element's attributes; `{}` if none
|
||||||
- `.id` = the value of the element's id attribute; `nil` if not present
|
- `.id` = the value of the element's id attribute; `nil` if not present
|
||||||
@ -66,6 +71,8 @@ All tree elements provide, apart from `:select` and `()`, the following accessor
|
|||||||
- `:getcontent()` = the raw text between the opening and closing tags of the element; `""` if none
|
- `:getcontent()` = the raw text between the opening and closing tags of the element; `""` if none
|
||||||
- `.nodes` = an array with the element's child elements, `{}` if none
|
- `.nodes` = an array with the element's child elements, `{}` if none
|
||||||
- `.parent` = the elements that contains this element; `root.parent` is `nil`
|
- `.parent` = the elements that contains this element; `root.parent` is `nil`
|
||||||
|
|
||||||
|
###Other
|
||||||
- `:gettext()` = the raw text of the complete element, starting with `"<tagname"` and ending with `"/>"`
|
- `:gettext()` = the raw text of the complete element, starting with `"<tagname"` and ending with `"/>"`
|
||||||
- `.level` = how deep the element is in the tree; root level is `0`
|
- `.level` = how deep the element is in the tree; root level is `0`
|
||||||
- `.root` the root element of the tree; `root.root` is `root`
|
- `.root` the root element of the tree; `root.root` is `root`
|
||||||
|
Loading…
Reference in New Issue
Block a user