Parsing iTunes RSS in R



I'm trying to parse the iTunes top 100 in R and spit out artist, song etc. but I'm having issues with the XML file, I guess. I was able to easily get useable data with Billboard's RSS (http://ift.tt/WVKMik)



GetBillboard <- function() {

hot.100 <- xmlTreeParse("http://ift.tt/WVKMik")
hot.100 <- xpathApply(xmlRoot(hot.100), "//item")

top.songs <- character(length(hot.100))

for(i in 1:length(hot.100)) {
top.songs[i] <- xmlSApply(hot.100[[i]], xmlValue)[3]
}
return(top.songs)

}


Trying similar strategies with iTunes, though (http://ift.tt/1C0IG0Q)



GetITunes <- function() {
itunes.raw <- getURL("http://ift.tt/1C0IG0Q")
itunes.xml <- xmlTreeParse(itunes.raw)
top.vids <- xpathApply(xmlRoot(itunes.xml), "//entry")
return(top.vids)
}


I just get nonsense:



> m <- GetITunes()
> m
list()
attr(,"class")
[1] "XMLNodeSet"
>


I'm guessing it's the formatting of the XML file. How can I get these iTunes data to fall into a similar structure as the data from Billboard at this point in the first function?



hot.100 <- xpathApply(xmlRoot(hot.100), "//item")


Thanks!


No comments:

Post a Comment