ntrax
ntrax

Reputation: 457

Get text of a cell table with R and XPath

i'm a begginer with R and XPath, i'm trying to scraping objects in CRAN to learn how scraping works.

i want to get dependences from a package at http://cran.r-project.org/web/packages/XML/index.html

the elements are "bitops, RCurl"

XPath should be this one /html/body/table/tbody/tr[4]/td[2]

and this is my R code

urlContent <- htmlParse("http://cran.r-project.org/web/packages/abc/index.html")
xpathSApply(doc=urlContent,path="/html/body/table/tbody/tr[4]/td[2]")

but i can't understand where is the problem, can you help me?

Upvotes: 0

Views: 215

Answers (1)

agstudy
agstudy

Reputation: 121588

Another smart option is to use readHTMLTable and avoid to write xpath.

Here I am reading the first table than I am accessing the row where the first column is eaqual to Suggests:.

library(XML)
dat <- readHTMLTable('http://cran.r-project.org/web/packages/XML/index.html')[[1]]
dat[dat[,1] == "Suggests:",]
Version:      3.96-1.1
3 Suggests: bitops, RCurl

Upvotes: 1

Related Questions