Returns the text of the elements matching a selector, and NA when there
are none, so that a missing field on one page stays one missing value in a
table instead of an error or a vector of length zero.
Value
A character vector: one element per match, or a single string if
collapse is given; NA if nothing matches.
See also
Other html:
html_paragraphs(),
prefer_html_text(),
read_html_blocks()
Examples
page <- xml2::read_html("<p class='a'>One</p><p class='a'>Two</p>")
html_text_or_na(page, "p.a")
#> [1] "One" "Two"
html_text_or_na(page, "p.a", collapse = "\n")
#> [1] "One\nTwo"
html_text_or_na(page, "p.b")
#> [1] NA