【发布时间】:2014-02-07 21:13:12
【问题描述】:
我正在尝试将 csv 文件第一列中的值增量加载到 URL 中,并以 5 秒的延迟一次请求一个 URL。第一列中的每个值都应替换“theid”
这是我目前的代码:
# I have a defined function
def withid (theid):
""""""
global cache
dupe = False
theurl = "{0}{1}{2}".format(OMDBURL, "?i=", theid)
response = urllib2.urlopen(theurl)
movdata = json.load(response)
for mov in cache:
if movdata[MKEY[1]] == mov[MKEY[1]]:
dupe = True
if not dupe:
cache.append(movdata)
outfile2 = open('outputrows2-shortened.csv', 'rb')
for row in outfile2:
theid = outfile2(row[0])
time.sleep(5)
输出:TypeError:“文件”对象不可调用
【问题讨论】:
-
还有……有什么问题?
-
它不起作用,我只是收到上面的错误消息
-
那是因为
withid(现在)返回一个字典;您想将其附加到 jsonlist,而不是相反。请改用jsonlist.append(withid(row[0]))。 -
不幸的是,我收到了一个 HTTP 错误,意思是,我认为该 url 没有填充来自该列的数据
标签: python html json parsing csv