I'm trying webscrape tax-rates.org to get the average percentage for each county in Texas. I have a list of 255 counties in the csv file that I import as "TX_counties", this is one column table. I need to create a URL for each county as a string, so I set d1 in the first cell using [i, 1], then concatenated it into a URL string, did a cleanup, and then added +1 to [i], which does he go to the second cell for the next county name, and the process continues.
The problem is that I cannot figure out how to save the scrape results in a "growing list", which I then want to make in a table and save it in a CSV file at the end. I can only scratch one county at a time and then rewrite myself.
Any thoughts? (quite new to R and the scraper in general)
i <- 1
for (i in 1:255) {
d1 <- as.character(TX_counties[i,1])
uri.seed <- paste(c('http://www.tax-rates.org/texas/',d1,'_county_property_tax'), collapse='')
html <- htmlTreeParse(file = uri.seed, isURL=TRUE, useInternalNodes = TRUE)
avg_taxrate <- sapply(getNodeSet(html, "//div[@class='box']/div/div[1]/i[1]"), xmlValue)
t1 <- data.table(d1,avg_taxrate)
i <- i+1
}
write.csv(t1,"2015_TX_PropertyTaxes.csv")
source
share