我才刚刚开始学习编码,如果这个问题很小,我想提前道歉。在
下面是我复制粘贴的脚本。在import urllib2 # works fine with Python 2.7.9 (not 3.4.+)
import json
import time
def fetchPreMarket(symbol, exchange):
link = "http://finance.google.com/finance/info?client=ig&q="
url = link+"%s:%s" % (exchange, symbol)
u = urllib2.urlopen(url)
content = u.read()
data = json.loads(content[3:])
info = data[0]
t = str(info["elt"]) # time stamp
l = float(info["l"]) # close price (previous trading day)
p = float(info["el"]) # stock price in pre-market (after-hours)
return (t,l,p)
p0 = 0
while True:
t, l, p = fetchPreMarket("AAPL","NASDAQ")
if(p!=p0):
p0 = p
print("%s\t%.2f\t%.2f\t%+.2f\t%+.2f%%" % (t, l, p, p-l,
(p/l-1)*100.))
time.sleep(60)
这似乎是一个伟大的代码,但当我运行它时,我得到以下错误消息
^{pr2}$
我试图修改fetchPreMarket,使其只输出info = data[0],但当我尝试“print info”时,却一无所获。在
提前谢谢