Created
December 6, 2013 14:18
-
-
Save deckerego/7824930 to your computer and use it in GitHub Desktop.
Reading an RSS XML Feed as a Dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rssToDataframe <- function(uri) { | |
doc <- getURL(uri) | |
doc <- xmlParse(doc) | |
src <- xpathApply(doc, "/rss/channel/item") | |
items.df <- data.frame() | |
if(length(src) > 0) { | |
for(i in 1:length(src)) { | |
item <- xmlSApply(src[[i]], xmlValue) | |
record.df <- data.frame(t(item), stringsAsFactors=FALSE) | |
items.df <- rbind(items.df, record.df) | |
} | |
} | |
items.df$pubDate <- strptime(items.df$pubDate, "%a, %d %b %Y %H:%M:%S", tz="GMT") | |
return(items.df) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment