python - How do I query this (json looking) data? -
i have data coming via api , want pull "confidence" scores in there. how go doing that:
{ "time": 765, "annotations": [ { "start": 106, "end": 115, "spot": "customers", "confidence": 0.7198, "id": 234206, "title": "customer", "uri": "h''ttp://en.wikipedia.org/wiki/customer", "label": "customer" }, { "start": 116, "end": 122, "spot": "online", "confidence": 0.6313, "id": 41440, ''"title": "online , offline", "uri": "http://en.wikipedia.org/wiki/online_and_offline", "label": "online" }, { "start": 138, "end": 143, "s''pot": "small", "confidence": 0.7233, "id": 276495, "title": "small business", "uri": "http://en.wikipedia.org/wiki/small_business", "label''": "small business" } ] }
i tried doing things data["confidence"]
, didn't seem pull confidence figures. how pull confidence figures in python? thank in advance.
this code retrieves data:
import requests api_key = insert api key content_urls = "http://www.startupdonut.co.uk/sales-and-marketing/promote-your-business/using-social-media-to-promote-your-business" url = "https://api.dandelion.eu/datatxt/nex/v1/?lang=en &url="+content_urls+"&token=" + api_key request = requests.get(url) data in request: print (data)
your api response data looks this:
{ "time": 765, "annotations": [ { "start": 106, "end": 115, "spot": "customers", "confidence": 0.7198, "id": 234206, "title": "customer", "uri": "h''ttp://en.wikipedia.org/wiki/customer", "label": "customer" }, { "start": 116, "end": 122, "spot": "online", "confidence": 0.6313, "id": 41440, ''"title": "online , offline", "uri": "http://en.wikipedia.org/wiki/online_and_offline", "label": "online" } ] }
to extract condidence can use code:
import json # ... request formation code goes here response = requests.get(url) data = response.json() # or data = json.loads(response.content) confidence_values = [] annotation in data['annotations']: confidence_values.append(annotation.get('confidence')) print(confidence_values)
Comments
Post a Comment