| html_attr {rvest} | R Documentation |
html_attr() gets a single attribute; html_attr() gets all attributes.
html_attr(x, name, default = NA_character_) html_attrs(x)
x |
A document (from |
name |
Name of attribute to retrieve. |
default |
A string used as a default value when the attribute does not exist in every element. |
A character vector (for html_attr()) or list (html_attrs())
the same length as x.
url <- "https://en.wikipedia.org/w/index.php?title=The_Lego_Movie&oldid=998422565"
html <- read_html(url)
cast <- html_elements(html, "tr:nth-child(8) .plainlist a")
cast %>% html_text2()
cast %>% html_attrs()
cast %>% html_attr("href")
# If needed, use url_absolute() to convert to complete urls
url_absolute(html_attr(cast, "href"), url)