如果我手动键入一行地址,则对api的以下调用有效。我的目标是为整个数据集实现自动化,我认为forloop就足够了。
set_zillow_web_service_id("X1-ZWz17seirkzuh7_93aho")
xml <- GetDeepSearchResults(address='600 S. Quail Ct.', citystatezip ='67114',
rentzestimate=FALSE)
dat <- unlist(xml)
str(dat)
dat <- as.data.frame(dat)
dat <- gsub("text","", dat$dat)
head(dat, 20)
path <- "http://www.zillow.com/webservice/GetDeepSearchResults.htm"
request <- GET(url = path,
query = list(
zws-id = 'X1-ZWz17seirkzuh7_93aho',
address = sample3$Street,
citystatezip = sample3$ZipCode,
rentzestimate=FALSE)
)
我正在尝试从zillow的Deepsearch结果端点提取API输出
我的样本数据集如下:
> sample3 <- tibble::tribble(
+ ~ZipCode, ~Total, ~ZipHhIncome, ~Street, ~State,
+ 43130, 0, 46205, "2577 Long Bow Ave", "OH",
+ 44718, 0, 69396, "4822 Armandale Nw", "OH",
+ 8837, 0, 74764, "348 Grandview Ave", "NJ"
+ )
>
> head(squads)
# A tibble: 3 x 5
ZipCode Total ZipHhIncome Street State
<dbl> <dbl> <dbl> <chr> <chr>
1 43130 0 46205 2577 Long Bow Ave OH
2 44718 0 69396 4822 Armandale Nw OH
3 8837 0 74764 348 Grandview Ave NJ
以上只是我拥有的5k行中前3行数据的表示形式。我想编写一个循环遍历每行邮政编码,街道并给我输出的循环。
下面是我的forloop:
for (i in 1:nrow(sample3)) {
api_output <- GetDeepSearchResults(Street[i,],Zipcode[i,]))
result <- cbind(addresses[i,],api_output)
latlon <- rbind.fill(latlon,result, fill = NULL)
ScriptPause(1)
print(i)
当我打印(i)时,出现错误消息:
> print(i)
Error in print(i) : object 'i' not found
还有更好的方法吗?我该怎么做?