How To Use XPath within R

Posted by Agung Pambudi in ,
xpathSApply is a version of xpathApply which attempts to simplify the result if it can be converted to a vector or matrix rather than left as a list. In this way, it has the same relationship to xpathApply as sapply has to lapply.

XPath. (source:

My code within R:

R> doc <- htmlParse("")
R> xpathSApply(doc, "//head/meta[@name=\"description\"]") 

# which returns
<meta name="description" content="[Archive]  Simburgur's Live Stream [Offline] Gears of War 3" />

Obviously, in this example, all I want is what is inside the quotes of content=



This still selects an attribute node, but probably there is an easy way in your PL to get the string value of the attribute.

To get just the string value, use:


Do note: Using the // abbreviation may result in very slow evaluation of the XPath expression, because it may cause a linear traversal of a whole (sub)tree.


[Archive] Simburgur's Live Stream [Offline] Gears of War 3

No comments:

Post a Comment