Skip to content
Prev 201577 / 398506 Next

XML package example code?

Cls59 is correct that there is a lot of example code, just look in ?
htmlTreeParse and you'll get most of what you need i think.

here's some simplified code I use a lot of (XPath expressions are used
to parse the code):

# libraries
library(RCurl)
library(XML)

# google url
my.url <- "http://www.google.co.uk/search?hl=en&client=firefox-
a&rls=org.mozilla%3Aen-GB%3Aofficial&hs=6Sd&q=google
+wave&btnG=Search&meta=&aq=f&oq="

# download page
html <- getURL(my.url)
html.tree <- htmlTreeParse(html, useInternalNodes = TRUE, error =
function(...){})

# the xpath expression is next
nodes <- getNodeSet(html.tree, "//a[@href][@class='l']")
links <- sapply(nodes, function(x) x <- xmlAttrs(x)[[1]])


HTH
Tony
On 25 Nov, 01:49, Peng Yu <pengyu... at gmail.com> wrote: