Extract HTML Attribute | EXTRACT_HTML_ATTRIBUTE
Syntax
EXTRACT_HTML_ATTRIBUTE( [html], [selector], [attribute], [returnList = false] )
Parameters
html
An HTML string
selector
A CSS selector to query the HTML document
attribute
The attribute of the matched HTML element to return
returnList optional
When TRUE, all matching results are returned as a LIST in the order they are found in the document. When FALSE, only the first found result is returned.
Return Value
A TEXT value of the matched attributeDescription
Query an HTML string to extract an attribute value of the matched element.Examples
# VALUE is '<!doctype HTML><html><body><div id="mydiv" someprop="example value"><p>This is an example paragraph</p><p>This is <i>another</i> example paragraph</p></div></body></html>'
EXTRACT_HTML_ATTRIBUTE(VALUE, "#mydiv", "someprop")
# Returns 'example value'
# VALUE is '<!doctype HTML><html><body><div id="mydiv" someprop="hello there"><p class="first">This is an example paragraph</p><p class="second">This is <i>another</i> example paragraph</p></div></body></html>'
EXTRACT_HTML_ATTRIBUTE(VALUE, "#mydiv p", "class", true)
# Returns ['first', 'second']
# VALUE is '<!doctype HTML><html><body><div id="mydiv" someprop="hello there"><p class="uno">This is an example paragraph</p><p class="dos">This is <i>another</i> example paragraph</p></div></body></html>'
EXTRACT_HTML_ATTRIBUTE(VALUE, "#mydiv p span", "id")
# Returns NULL