1
我試圖讓雅虎價格進入sqlite的...... 我有下面的代碼,但不能使數據進入ipull [] 然後進入源碼...中獲取數據的SQLite從雅虎金融
from urllib import urlopen
import win32com.client as win32
import sqlite3
RANGE = range(3, 8)
COLS = ('TICKER', 'PRICE', 'Vol')
URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1v'
TICKS = ('GGP', 'JPM', 'AIG', 'AMZN')
ipull =[]
def excel():
app = 'Excel'
xl = win32.gencache.EnsureDispatch('%s.Application' % app)
ss = xl.Workbooks.Add()
sh = ss.ActiveSheet
xl.Visible = True
for x in range(3):
sh.Cells(5, x+1).Value = COLS[x]
row = 6
u = urlopen(URL % ','.join(TICKS))
for data in u:
tick, price, per = data.split(',')
sh.Cells(row, 1).Value = eval(tick)
sh.Cells(row, 2).Value = ('%.2f' % float(price))
sh.Cells(row, 3).Value = eval(per.rstrip())
row += 1
u.close()
con = sqlite3.connect('/py/data/db2')
c = con.cursor()
c.execute('INSERT INTO prices VALUES (?,?,?)', ipull)
con.commit()
c.close()
if __name__=='__main__':
excel()
你面對的錯誤是什麼? – viksit 2010-08-24 03:57:42
'excel'似乎並沒有在'ipull'中放入任何數據,所以你認爲應該怎麼做? – 2010-08-24 04:19:48
首先,我是python的新手...並且在一般生活中。 我用一個樣本從雅虎獲取數據到excel中。這工作足以建立以後... 但是,我要遠離excel。我添加了sqlite代碼..並卡住了。 「用於u中的數據:」獲取數據並保存它,然後放到excel中。 如何從「爲u:中的數據」獲取數據爲ipull .....那麼問題(我認爲)「在ipull中的行:」將加載到Sqlite中。 如果我可以加載到excel和sqlite中,這將是非常好的。謝謝您的幫助 – Merlin 2010-08-24 05:52:10