Description Usage Arguments Details Value Examples
Consider the following case : on an html page you have information about several people. Several informations are included in a div of class "people", but for some people some information is missing.
1 | cssApplyInNodeSet(doc, path, relPath, fun, prefix = "./", ...)
|
doc |
An html document parsed with |
path |
Character. It CSS path used to identify elements where to search the information |
relPath |
Character. CSS path used to select elements in the elements selected with "path" |
fun |
Function to apply to the selected nodes. |
prefix |
Should be "./" if the first element in relPath has to be the child of the elements selected by "path", or ".//" if it may be any descendent (and not necessarily a direct child). |
... |
Parameters passed to " |
With this function, you can first select all divs of class "people" and then search inside them if the information is available. If not, the function will return a NA value for the person.
If no element in the html document corresponds to "path", the function will return an empty list. Else it will return a list of length equal to the number of elements selected.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | doc <- "<html>
<head></head>
<body>
<div id='character1' class='character'>
<span class='name'>Mike</span>
<span class='level digit'>10</span>
</div>
<div id='character2' class='character'>
<span class='name'>Stan</span>
</div>
</body>
</html>"
doc <- htmlParse(doc)
# Level of characters
cssApply(doc, ".character>.level", cssNumeric)
# character 2 does not have level, we would want to have a NA value instead of nothing
cssApplyInNodeSet(doc, ".character", ".level", cssNumeric)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.