I'm building a crawler to extract data and I'm having trouble categorizing it all when I get it. It seems that the dict key I was expecting to use will not pull what I am looking for. I want to extract "member_id" and "vote_position".
The example below shows an attempt to pull using the "positions" key. Using "positions", "member_id", "vote_position" all yield the same KeyError.
Moving farther down you can see the output when using print data
. Still, using the keys displayed after print data
output still yields KeyError.
I'm feeling pretty stumped. Any help would be greatly appreciated.
import urllib2
import json
api_key = '72c9a68****************************'
url = 'http://api.time.com/svc/politics/v3/us/legislative/blue/113/
json_obj = urllib2.urlopen(url)
data = json.load(json_obj)
print data['positions']
Traceback (most recent call last):
File "/Users/Owner/PycharmProjects/untitled2/1", line 8, in <module>
print data [positions]
NameError: name 'positions' is not defined
JSON Data:
"positions": [
{
"member_id": "A000055",
"vote_position": "Yes",
"dw_nominate": "0.466"
},
{
"member_id": "A000367",
"vote_position": "Yes",
"dw_nominate": "0.995"
},
a simple print data
yields:
{u'dw_nominate': u'-0.311', u'vote_position': u'Yes', u'member_id': u'B001242'}, {u'dw_nominate': u'0.793', u'vote_position': u'Yes', u'member_id': u'B001250'}, {u'dw_nominate': u'0.728', u'vote_position': u'Yes', u'member_id': u'B001273'}