from googlefinance import getQuotes
import json
import time as t
import re
List = ["A","AA","AAB"]
Time=t.localtime() # Sets variable Time to retrieve date/time info
Date2= ('%d-%d-%d %dh:%dm:%dsec'%(Time[0],Time[1],Time[2],Time[3],Time[4],Time[5])) #formats time stamp
while True:
for i in List:
try: #allows elements to be called and if an error does the next step
Data = json.dumps(getQuotes(i.lower()),indent=1) #retrieves Data from google finance
regex = ('"LastTradePrice": "(.+?)",') #sets parse
pattern = re.compile(regex) #compiles parse
price = re.findall(pattern,Data) #retrieves parse
print(i)
print(price)
except: #sets Error coding
Error = (i + ' Failed to load on: ' + Date2)
print (Error)
它会将引号显示为:['(number)']
。
我希望它只显示数字,这意味着删除括号和引号。
任何帮助都会很棒。
答案 0 :(得分:1)
更改:
print(price)
成:
print(price[0])
打印出来:
A
42.14
AA
10.13
AAB
0.110
答案 1 :(得分:0)
尝试使用type()
函数来了解数据类型,在您的情况下type(price)
它的数据类型是列表使用print(price[0])
您将获得output (number)
,因为您需要查看Google数据和正则表达式。