【发布时间】:2016-11-18 21:53:39
【问题描述】:
我正在尝试根据 ISBN 从 API (http://www.knigoed.info/api-prices.html) 获取图书价格数据。
这个想法是向函数提交 ISBN 的向量,以获取包含所有可用信息的数据框(或至少包含来自不同供应商的价格的 Data.Frame)
isbns<- c("9785170922789", "9785170804801", "9785699834174", "9785699717255", "9785170869237")
getISBNprice <- function(ISBN, source="http://www.knigoed.info/api/Prices?code=") {
pathA <- source
for (i in 1:length(ISBN)) {
ISB <- ISBN[i]
AAA <- paste(pathA, ISB, "&sortPrice=DESC&country=RU", sep="")
document <- fromJSON(AAA, flatten = FALSE)
dfp <- document$prices
dfp <- cbind(dfp,ISB )
# dfp <- cbind(dfp,BookID=document$bookId)
# dfp <- cbind(dfp,Title=document$title)
# dfp <- cbind(dfp,Author=document$author)
# dfp <- cbind(dfp,Publisher=document$publisher)
# dfp <- cbind(dfp,Series=document$series)
# dfp <- cbind(dfp,Picture=document$picture)
if (!exists("AAAA")) {AAAA<- dfp} else {bind_rows(AAAA, dfp) }
}
AAAA
}
但是函数返回错误: 1. 在 bind_rows_(x, .id) 中:不等因子级别:强制转换为字符 2:在 bind_rows_(x, .id) 中:不等因子级别:强制转换为字符 3:在 bind_rows_(x, .id) 中:不等因子级别:强制转换为字符 4:在 bind_rows_(x, .id) 中:不等因子级别:强制转换为字符
【问题讨论】:
标签: json r api loops dataframe