Skip to contents

Same scanner as the XML path but tolerant of HTML quirks: void elements (<br>, <img>, ...) never push the stack, unclosed <p>/<li> close implicitly, and stray end tags are ignored rather than fatal.

Usage

morie_fetch_html(txt)

Arguments

txt

HTML text.

Value

A nested list tree as in morie_fetch_xml.

Examples

html <- "<html><body><p>first<p>second<br><ul><li>a<li>b</ul></body></html>"
root <- morie_fetch_html(html)
root
#> $tag
#> [1] "html"
#> 
#> $attrs
#> list()
#> 
#> $children
#> $children[[1]]
#> $children[[1]]$tag
#> [1] "body"
#> 
#> $children[[1]]$attrs
#> list()
#> 
#> $children[[1]]$children
#> $children[[1]]$children[[1]]
#> $children[[1]]$children[[1]]$tag
#> [1] "p"
#> 
#> $children[[1]]$children[[1]]$attrs
#> list()
#> 
#> $children[[1]]$children[[1]]$children
#> list()
#> 
#> $children[[1]]$children[[1]]$text
#> [1] "first"
#> 
#> 
#> $children[[1]]$children[[2]]
#> $children[[1]]$children[[2]]$tag
#> [1] "p"
#> 
#> $children[[1]]$children[[2]]$attrs
#> list()
#> 
#> $children[[1]]$children[[2]]$children
#> $children[[1]]$children[[2]]$children[[1]]
#> $children[[1]]$children[[2]]$children[[1]]$tag
#> [1] "br"
#> 
#> $children[[1]]$children[[2]]$children[[1]]$attrs
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[1]]$children
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[1]]$text
#> [1] ""
#> 
#> 
#> $children[[1]]$children[[2]]$children[[2]]
#> $children[[1]]$children[[2]]$children[[2]]$tag
#> [1] "ul"
#> 
#> $children[[1]]$children[[2]]$children[[2]]$attrs
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children
#> $children[[1]]$children[[2]]$children[[2]]$children[[1]]
#> $children[[1]]$children[[2]]$children[[2]]$children[[1]]$tag
#> [1] "li"
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[1]]$attrs
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[1]]$children
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[1]]$text
#> [1] "a"
#> 
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[2]]
#> $children[[1]]$children[[2]]$children[[2]]$children[[2]]$tag
#> [1] "li"
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[2]]$attrs
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[2]]$children
#> list()
#> 
#> $children[[1]]$children[[2]]$children[[2]]$children[[2]]$text
#> [1] "b"
#> 
#> 
#> 
#> $children[[1]]$children[[2]]$children[[2]]$text
#> [1] ""
#> 
#> 
#> 
#> $children[[1]]$children[[2]]$text
#> [1] "second"
#> 
#> 
#> 
#> $children[[1]]$text
#> [1] ""
#> 
#> 
#> 
#> $text
#> [1] ""
#>