Skip to content

Instantly share code, notes, and snippets.

@joachifm
Last active September 26, 2015 19:38
Show Gist options
  • Save joachifm/1148904 to your computer and use it in GitHub Desktop.
Save joachifm/1148904 to your computer and use it in GitHub Desktop.
Match history scraper
library(XML)
url <- "http://eu.battle.net/sc2/en/profile/2007578/1/joachifm"
scrape.matchhistory <- function(profile.url) {
url <- paste(profile.url, "/matches", sep="")
doc <- htmlTreeParse(url, useInternalNodes=T)
thead <- xpathSApply(doc, "//*/table[@class='data-table']/thead/tr/th", xmlValue)
tbody <- xpathSApply(doc, "//*/table[@class='data-table']/tbody/tr/td", compose(trim, xmlValue))
m <- matrix(tbody, ncol=length(thead), byrow=T)
f <- as.data.frame(m, stringsAsFactors=F)
names(f) <- thead
f
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment