Created
December 19, 2012 22:37
-
-
Save abelsonlive/4341189 to your computer and use it in GitHub Desktop.
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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")