如何把从雅虎财经请求到的数据储存为本地的csv文件

import urllib2
import StringIO
h = urllib2.HTTPHandler(debuglevel = 0)
reqStockData = urllib2.Request('http://ichart.yahoo.com/table.csv?s=000001.SS&a=07&b=4&c=2010&d=11&e=31&f=2010&g=d')
opener = urllib2.build_opener(h)
data = opener.open(reqStockData)
inputStream = StringIO.StringIO(data.read())
try:
    f = open('d:\\a.csv','w')
    while True:
        byte = inputStream.next()
        f.write(byte)
except StopIteration,e:
    f.close()

#然后可以用python自带的csv模块进行读取

import csv
readCsv = csv.reader(open('d://a.csv'))
for Date,Open,High,Low,Close,Volume,adjClose in readCsv:
    print Date

进一步阅读:

http://www.pythonclub.org/python-files/csv

你可能感兴趣的:(C++,c,python,Yahoo,F#)