如何使用R

时间:2018-04-12 17:40:50

标签: r zillow

我从以前的同事那里继承了一个文件,用R来拉Zillow" Zestimate"和"租住Zestimate"属性的数据,然后将这些数据点输出到CSV文件。但是,我对编码很陌生,并且没有成功地提取我知道可用的其他信息。我在网站上搜索了答案,但由于我仍在努力学习如何编码,因此我已经成功地对当前代码进行了自己的编辑。任何帮助我可以添加代码来提取任何这些额外的数据点将非常感激。

  • 物业详情(平方英尺,年建,床,浴室,物业类型)
  • Zestimate范围(高和低)
  • 租住Zestimate范围(高和低)
  • 上次售出日期和价格
  • 价格历史记录(最新事件,日期和价格)(不确定是否可以废弃)
  • 税务历史(最新年度和财产税)(不确定是否可以废除)

当前代码:

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 = "")))

1 个答案:

答案 0 :(得分:0)

希望您已解决此问题,但GetSearchResult API不会返回您要查找的所有结果。您可能必须调用GetUpdatedPropertyDetails API才能获取所有结果。