How do I extract the data from that URL? I only want to print out all the 'value'
import urllib
import re
import json
htmltext = urllib.urlopen("http://www.bloomberg.com/markets/api/bulk-time-series/price/AXP%3AUS?timeFrame=1_MONTH").read()
data = json.loads(htmltext)
print data
This is what the API display as a result from print url command:
[{u'lastPrice': 60.85, u'price': [{u'date': u'2016-03-04', u'value': 58.29}, {u'date': u'2016-03-07', u'value': 59}, {u'date': u'2016-03-08', u'value': 59.43}, {u'date': u'2016-03-09', u'value': 59.05}, {u'date': u'2016-03-10', u'value': 58.75}, {u'date': u'2016-03-11', u'value': 59.46}, {u'date': u'2016-03-14', u'value': 59.57}, {u'date': u'2016-03-15', u'value': 59.23}, {u'date': u'2016-03-16', u'value': 59.7}, {u'date': u'2016-03-17', u'value': 60.08}, {u'date': u'2016-03-18', u'value': 61.22}, {u'date': u'2016-03-21', u'value': 61.21}, {u'date': u'2016-03-22', u'value': 60.61}, {u'date': u'2016-03-23', u'value': 60.63}, {u'date': u'2016-03-24', u'value': 60.47}, {u'date': u'2016-03-28', u'value': 60.28}, {u'date': u'2016-03-29', u'value': 60.6}, {u'date': u'2016-03-30', u'value': 60.29}, {u'date': u'2016-03-31', u'value': 61.4}, {u'date': u'2016-04-01', u'value': 61.1}], u'priceMinDecimals': 2, u'nyTradeEndTime': u'16:30:00.000', u'lastUpdateDate': u'2016-04-04', u'nyTradeStartTime': u'09:30:00.000', u'id': u'AXP:US', u'timeZoneOffset': -4, u'dateTimeRanges': {}}]
答案 0 :(得分:0)
You can get all the values this way. Get the first item in the data list (there's only 1 item). The get the price
list, then iterate over all the price dictionaries and retrieve the value
field for each one.
values = [p['value'] for p in data[0]['price']]