| html_attr | R Documentation |
html_attr() reads one attribute from every node; html_attrs() reads
all of them; html_classes() splits the class attribute into tokens.
Values are decoded (& becomes &). An attribute that is present
but empty is "", distinct from an absent one: test a boolean attribute
such as disabled by presence, !is.na(html_attr(x, "disabled")).
html_attr(x, name, default = NA_character_)
html_attrs(x)
html_classes(x)
x |
A |
name |
The attribute name: a single string. |
default |
The value for nodes that lack the attribute, including
nodes that are not elements: a single string, possibly |
Attribute names on HTML elements match regardless of ASCII case, as in a
browser; on SVG and MathML elements they match exactly (viewBox).
Namespaced attributes in foreign content are named with their prefix, as
in "xlink:href". Where an element has the same attribute more than
once, the first wins, as the HTML parser decides.
html_attr(): a character vector as long as x; NA for missing
nodes.
html_attrs(): a list as long as x of named character vectors, in
source order; NA_character_ for missing nodes.
html_classes(): a list as long as x of character vectors of class
tokens; NA_character_ for missing nodes.
Other node values:
html_markdown(),
html_name(),
html_serialize(),
html_strings(),
html_text(),
html_text_clean()
doc <- html_parse(
"<a href='/x' class='btn primary' data-id=7>Go</a><input disabled>"
)
body <- html_children(html_root(doc))[2]
nodes <- html_children(body)
html_attr(nodes, "href")
html_attr(nodes, "href", default = "")
html_attrs(nodes)
html_classes(nodes)
!is.na(html_attr(nodes, "disabled"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.