아하
생활

생활꿀팁

탈퇴한 사용자
탈퇴한 사용자

json 파싱 코드 에러 질문입니다.

https://pubchem.ncbi.nlm.nih.gov/rest/pug_view/annotations/heading/json?heading=Acid%20Value

위에 보기 불편 하시면

http://jsoneditoronline.org/#left=local.hacowe&right=local.vexezi

여기에 붙여 넣어주시면 됩니다.

여기에서 CID 값을 얻고 싶은데

=========================================================================

import requests

import json


host = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug_view'

path = '/annotations/heading/json?heading=Acid%20Value'

url = host + path
a = requests.get(url)b = a.json()

for data in b["Annotations"]["Annotation"]:

print(data["LinkedRecords"][0]["CID"][0])

============================================================================

위 코드를 돌리면

KeyError: 'LinkedRecords'

에러가 뜹니다.

어떻게 해야할까요?

2개의 답변이 있어요!