Reads one <ul> or <ol> element. In "text" mode, the result has one
string per item: the item's cleaned text (see html_text_clean()),
without the text of any list nested inside it, so child items do not
leak into their parent. A nested list still separates the text around
it with a line break. In "tree" mode, nested lists become children
of the item that contains them, including lists inside wrapper elements
such as <div>.
Usage
html_list(x, mode = c("text", "tree"))Arguments
- x
A
zuhtml_nodesetholding exactly one<ul>or<ol>element, as fromhtml_element().- mode
"text"or"tree".
Value
"text": a character vector, one string per item."tree": an object of classzuhtml_list, a list withtype("ul"or"ol") anditems, a list with one element per item; each item is a list withtext(as in text mode) andchildren(a list ofzuhtml_listobjects, one per list nested in the item).
Details
Items are the <li> children of the list, in source order; empty items
are "" and duplicates are kept.
See also
Other extraction:
html_forms(),
html_links(),
html_table(),
html_table_cells(),
html_url()
Examples
doc <- html_parse("<ul><li>Apples<li>Tools<ul><li>Hammer<li>Saw</ul></ul>")
items <- html_element(doc, "ul")
html_list(items)
#> [1] "Apples" "Tools"
html_list(items, mode = "tree")
#> <zuhtml_list ul, 2 items>
#> - Apples
#> - Tools
#> - Hammer
#> - Saw