0

I inherited a file from a previous coworker to use R to pull Zillow "Zestimate" and "Rent Zestimate" data for properties, and then output these data points to a CSV file. However, I am very new to coding and have not been successful with pulling additional information that I know is available. I have searched the site for answers, but since I am still trying to learn how to code I haven't been successful with making my own edits to the current code. Any help I can get adding code to pull any of these additional data points would be much appreciated.

  • Property details (sqft, year built, beds, baths, property type)
  • Zestimate range (high and low)
  • Rent Zestimate range (high and low)
  • Last sold date and price
  • Price history (latest event, date, and price)(not sure this can be scraped )
  • Tax history (latest year and property taxes) (not sure this can be scraped )

Current code:

houseAddsSplit = read.csv(houseAddsFileLocation)  zillowAdds = paste(houseAddsSplit$STREET, houseAddsSplit$CITY, houseAddsSplit$STATE, houseAddsSplit$ZIP, sep = " ")  
library(ZillowR)  
library(XML)
set_zillow_web_service_id(zwsId)  
zpidList = NULL  
zestimate = NULL  
rentZestimate = NULL  
for(i in 1:length(zillowAdds)){  
  print(paste("Processing house: ", i, ", address: ", zillowAdds[i]))  
  print(zillowAdds[i])  
  houseZpidClean = "ERR"  
  houseZestClean = "ERR"  
  houseRentZestClean = "ERR"  
  houseInfo = try(GetSearchResults(address = zillowAdds[i], citystatezip = as.character(houseAddsSplit$ZIP[i]), rentzestimate = TRUE))  
 '#'while(houseInfo$message$code != "0"){  
 '#'  houseInfo = try(GetSearchResults(address = cipAdds[i], citystatezip = as.character(cipLoans$ZIP[i]), rentzestimate = TRUE))  
 '#'  Sys.sleep(runif(1, 3, 5))  
 '#'}  
if(houseInfo$message$code == "0"){  
    houseZpid = try(xmlElementsByTagName(houseInfo$response, "zpid", recursive = TRUE))  
    houseZest = try(xmlElementsByTagName(houseInfo$response, "amount", recursive = TRUE))  
    houseZpidAlmostClean = try(toString.XMLNode(houseZpid$results.result.zpid))  
    houseZestAC = try(toString.XMLNode(houseZest$results.result.zestimate.amount))  
    houseRentZestAC = try(toString.XMLNode(houseZest$results.result.rentzestimate.amount))  
    houseZpidClean = try(substr(houseZpidAlmostClean, 7, nchar(houseZpidAlmostClean) - 7))  
    houseZestClean = try(substr(houseZestAC, 24, nchar(houseZestAC) - 9))  
    houseRentZestClean = try(substr(houseRentZestAC, 24, nchar(houseRentZestAC) - 9))  
}
  
  closeAllConnections()
  
  zpidList[i] = houseZpidClean  
  print(paste("zpid: ", houseZpidClean))  
  zestimate[i] = houseZestClean  
  print(paste("zestimate: ", houseZestClean))  
  rentZestimate[i] = houseRentZestClean  
  print(paste("rent zestimate: ", houseRentZestClean))  
  Sys.sleep(runif(1, 7, 10))  
}  
outputData = cbind(houseAddsSplit, zestimate, rentZestimate)  
write.csv(outputData, paste(writeToFolder, "/zillowPullOutput.csv", sep = ""))  
print(paste("All done. File written to", paste(writeToFolder, "/zillowPullOutput.csv", sep = "")))
ScottB
  • 1
  • 1

1 Answers1

0

Hope you solved this, but GetSearchResult API wouldn't return all the results you are looking for. You may have to call GetUpdatedPropertyDetails API to get all the results.

Gajanan Arha
  • 45
  • 2
  • 8