我是 python 新手,CSV 解析器有问题。这是代码:
import urllib2
import csv
u = urllib2.urlopen(r'http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=nab')
data = u.read()
reader = csv.reader(data)
for row in reader:
print row
雅虎返回这个原始 csv:
"Apple Inc.",482.09,482.00
"Google Inc.",877.20,876.94
"Microsoft Corpora",33.34,33.33
我想解析它并创建一个包含 3 个字段的简单 JSON 对象:Ticker、Bid、Offer
但是数据来自 csv.reader() ,如下所示:
['Apple Inc.']
['', '']
['4']
['8']
['2']
['.']
['5']
['5']
['', '']
['4']
['8']
['2']
['.']
['4']
['8']
[]
[]
['Google Inc.']
['', '']
['8']
['7']
['6']
['.']
['2']
['4']
['', '']
['8']
['7']
['6']
['.']
['1']
['0']
[]
[]
['Microsoft Corpora']
['', '']
['3']
['3']
['.']
['2']
['9']
['', '']
['3']
['3']
['.']
['2']
['8']
[]
[]
它似乎打破了每个数字的行。关于我在这里做错了什么的任何想法?