Skip to content

Instantly share code, notes, and snippets.

@abelsonlive
Created December 19, 2012 22:37
Show Gist options
  • Save abelsonlive/4341189 to your computer and use it in GitHub Desktop.
Save abelsonlive/4341189 to your computer and use it in GitHub Desktop.
library("scraply") # also loads XML and plyr
tree <- url2tree("http://www.house.gov/representatives/#name_a")
nodes <- tree2node(tree, select='class="directory"')
data <- ldply(nodes, readHTMLTable)
write.csv(data, "representatives.csv", row.names=FALSE)
@abelsonlive
Copy link
Author

oddly, this page consists of two lists of representatives: one sorted by state, one by name. each is its separate div and is hidden when a user chooses to search by state / name. thus, when we run this scraper we get two versions of the same data. the only difference is that one has complete strings for districts while the other has an integer (unless the rep is "at large")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment