R, right xpath to grab the text using xpathSApply -
it's simple xpath exercise, cannot work.
when inspect element of button (using google chrom), gives tree - i'd grab title, such "distinguished contributor" or "board manager".
<span class="author-by"></span> <span class="username lia-user-name"> <img id="display_3" class="lia-user-rank-icon-left" alt="distinguished contributor" title="distinguished contributor"></img> ..... <span class="author-by"></span> <span class="username lia-user-name"> <img id="display_25" class="lia-user-rank-icon-left" alt="board manager" title="board manager"></img>
so far, tried
> xpathsapply(htmltree, "//img[@class='lia-user-rank-icon-left']", xmlgetattr, "href") > test = "//img/@title" > <- xpathsapply(htmltree, test, function(x) c(xmlvalue(x), xmlattrs(x)[["href"]]))
and bunch of others, wasn't successful yet. guidance appreciated!
it example getting source of images class 'dno'. think in case, have change 'dno' , 'src'.
library(rcurl) library(xml) text = geturl("http://stackoverflow.com/questions/23024062/r-right-xpath-to-grab-the-text-using-xpathsapply") d = htmlparse(text) l = xpathapply(d, "//img[@class='dno']") sapply(l, xmlgetattr, "src")
you can replace last 2 lines xpathapply(d, "//img[@class='dno']", xmlgetattr, "src")
. however, debugging purposes, better split 2 commands.
Comments
Post a Comment