Skip to content

Instantly share code, notes, and snippets.

@hadley
Created May 13, 2014 17:55
Show Gist options
  • Save hadley/bfcf043981f34a6f2309 to your computer and use it in GitHub Desktop.
Save hadley/bfcf043981f34a6f2309 to your computer and use it in GitHub Desktop.
library(httr)
library(XML)
library(selectr)
xpath <- function(x) structure(x, class = "xpath")
sel <- function(x) xpath(css_to_xpath(x, prefix = "//"))
url <- "http://www.boxofficemojo.com/movies/?id=ateam.htm"
html <- content(GET(url), "parsed")
"[.HTMLInternalDocument" <- function(x, i, ...) {
if (inherits(i, "xpath")) {
xpathApply(x, i)
} else {
NextMethod()
}
}
html[sel("center")]
html[sel("center font")]
html[sel("center font b")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment