I have been working on parsing a URL API and after some assistance from the community, I am now able to get an ordered list appearing via the following Python compilation:
.py Program:
import urllib, json
url = "http://www.cvedetails.com/json-feed.php?numrows=5&vendor_id=26&product_id=0&version_id=0&hasexp=1&opec=1&opov=1&opcsrf=1&opfileinc=1&opgpriv=0&opsqli=1&opxss=0&opdirt=0&opmemc=0&ophttprs=0&opbyp=0&opginf=0&opdos=0&orderby=0&cvssscoremin=0"
response = urllib.urlopen(url)
data = json.loads(response.read())
for index, entry in enumerate(data, 1):
print ('Item {}'.format(index))
for name, value in entry.items():
print '{}: {}'.format(name, value)`
Output in CLI:
Item 1 **<-Unpopulated**
Item 2 **<-Unpopulated**
Item 3 **<-Unpopulated**
Item 4 **<-Unpopulated**
Item 5 **<-Populated**
update_date: 2014-01-17
cve_id: CVE-2013-3906
exploit_count: 1
summary: GDI+ in Microsoft Windows Vista SP2 and Server 2008 SP2; Office 2003 SP3, 2007 SP3, and 2010 SP1 and SP2; Office Compatibility Pack SP3; and Lync 2010, 2010 Attendee, 2013, and Basic 2013 allows remote attackers to execute arbitrary code via a crafted TIFF image, as demonstrated by an image in a Word document, and exploited in the wild in October and November 2013.
url: http://www.cvedetails.com/cve/CVE-2013-3906/
publish_date: 2013-11-06
cvss_score: 9.3
cwe_id: 94`
However I am facing a problem where it only displays the last response of the JSON request. This API endpoint is configured to output 5 items and does when I query it with a cURL command. However not when I use the above to create a list in Python.
Could anyone help me with this? It is probably something elementary that I am missing.
You are executing the second loop only on the end, that's why you get only the one item. You should put the second loop inside the first one, so you loop over every entry
that you get:
for index, entry in enumerate(data, 1):
print ('Item {}'.format(index))
for name, value in entry.items():
print '{}: {}'.format(name, value)`