0

I was able to receive the data using an API get request, now I just need help printing a few objects. I'm having trouble because the objects I need are nested pretty deeply. Objects I need:

-cve ID -url ref -description -severity

json page: https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/

import requests
import json
import pprint

url = "https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/"
params = {"q": "CVE"}
response = requests.get(url, params)

data = json.loads(response.text)


pprint.pprint (data)

1 Answer 1

1
import requests
import json
import pprint

url = "https://services.nvd.nist.gov/rest/json/cve/1.0/CVE-2021-40463/"
params = {"q": "CVE"}

response = requests.get(url, params)

data = json.loads(response.content)    

pprint.pprint(data)

response.content will return the content of the response. after than:

cve ID: pprint.pprint(data['result']['CVE_Items'][0]['cve']['CVE_data_meta']['ID'])

url ref: pprint.pprint(data['result']['CVE_Items'][0]['cve']['references']['reference_data'][0]['url'])

description: pprint.pprint(data['result']['CVE_Items'][0]['cve']['description']['description_data'][0]['value'])

severity: pprint.pprint(data['result']['CVE_Items'][0]['impact']['baseMetricV2']['severity'])

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, Berkay. I tried CVE ID first and it just responded the entire page. It's interesting, it seems I was on the right page - I sorta tried what you typed on my own earlier, but no success. It's nested pretty complex.
CVE ID response for this url I get: 'CVE-2021-40463'. I edited my answer for the clarification.
You are welcome by the way. If the answer was useful could you please mark the answer as correct answer please ☺️. @Alexandra
Wow - how did you do that. Seems I just need to learn the ordering of nesting. Thanks, Berkay. I'll mark the answer as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.