You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Loading required package: ggplot2
## Google Maps API Terms of Service: http://developers.google.com/maps/terms.
## Please cite ggmap if you use it: see citation('ggmap') for details.
##
## Attaching package: 'ggmap'
##
## The following object is masked from 'package:magrittr':
##
## inset
# here the search is filtered to just homes for sale if there are less# filters in search, the code will need to be modified since the css might# be different for different types of results (eg. homes for sales vs new# homes vs homes for rent)url="http://www.zillow.com/homes/for_sale/Greenwood-IN/fsba,fsbo,fore,cmsn_lt/house_type/52333_rid/39.638414,-86.011362,39.550714,-86.179419_rect/12_zm/0_mmm/"# get list of houses for sales that appears on the pagehouselist<-url %>% html() %>% html_nodes("article")
# Extract zillow id for each listingzpid<-houselist %>% html_attr("id") %>% str_replace_all("zpid_", "")
# get the address for each listingstaddrlink<-houselist %>% html_node(".property-address a") %>% html_attr("href")
straddr<- sapply(strsplit(staddrlink, "/"), function(x) x[3])
straddr<- str_replace_all(straddr, "-", "")
lat_lon<- geocode(straddr, source="google")
lotsqft<-houselist %>% html_node(".lot-size") %>% html_text() %>% str_replace_all(",",
"")
lotsqft<- sapply(lotsqft, function(x) {
num<- as.numeric(str_extract_all(x, "(\\d*\\.)?\\d+"))
if (!is.na(num) & str_detect(x, "(ac|acre)")) {
num<-num*43560
}
num
})
yrbuilt<-houselist %>% html_node(".built-year") %>% html_text()
yrbuilt<- as.numeric(str_extract_all(yrbuilt, "\\d+"))
price<-houselist %>% html_node(".price-large") %>% html_text() %>% gsub("[\\$a-zA-Z,]",
"", .) %>% as.numeric()
# house parameters (number of beds, baths, house area)houseparams<-houselist %>% html_node(".property-data") %>% html_text()
houseparamsSplit<- strsplit(houseparams, ", ")
## get number of bedsnumbeds<- sapply(houseparamsSplit, function(x) as.numeric(strsplit(x[1], "")[[1]][1]))
## get number of bathsnumbaths<- sapply(houseparamsSplit, function(x) as.numeric(strsplit(x[1], "")[[1]][4]))
housesqft<- sapply(houseparamsSplit, function(x) strsplit(x[1], "")[[1]][7]) %>%
str_replace_all(",", "") %>% as.numeric()
# houseData <-# data.frame(zpid,price,yrbuilt,numbeds,numbaths,housesqft,lotsqft,straddr)houseData<-data.frame(zpid, price, yrbuilt, numbeds, numbaths, housesqft,
lotsqft, straddr, lat_lon)
kable(houseData)