我在解析API调用中的市值(它是一个数字)时遇到问题。我得到了数据,但出于我正在开发的程序的目的,我只需要数字,而不是其他东西。在
import csv
import intrinio
import requests
import json
import re
api_username = "b9cb2b8cbda8dde39f27a21f66e12afd"
api_password = "6d71a6dd01dd554f92a03f0e1b40dd44"
# CSV_URL = 'https://api.intrinio.com/financials/reported.csv?identifier=AAPL&statement=income_statement&fiscal_year=2015&fiscal_period=FY'
# CSV_URL2 = 'https://api.intrinio.com/financials/standardized.csv?identifier=AAPL&statement=balance_sheet&type=FY&fiscal_period=FY&date=2017-05-20'
CSV_URL3 = 'https://api.intrinio.com/data_point?identifier=AAPL&item=marketcap'
with requests.Session() as s:
download = s.get(CSV_URL3,auth=(api_username, api_password))
decoded_content = download.content.decode('utf-8')
cr = csv.reader(decoded_content.splitlines(), delimiter=',')
my_list = list(cr)
fx = open(r'test3.csv', 'w')
for item in my_list:
fx.write("%s\n" % item)
str1 = my_list[0][2]
num = re.findall('\d+', str1)
final_number = float(num[0])
print(final_number)
目前没有回答
相关问题 更多 >
编程相关推荐