viernes, 16 de marzo de 2018

open remote url with json

import urllib.request
import urllib.parse
import json
params = urllib.parse.urlencode({'cid': 1, 'did': 2})
url = "http://108.61.221.173/match_info.php?%s" % params
with urllib.request.urlopen(url) as f:
    a=f.read().decode('utf-8')

    print(type(a))
    d=json.loads(a)
    print(json.dumps(d))
    print(d['timer'])


/////////////////

comand   python3  get.py


result printed


<class 'str'> # type of variable
{"timer": 0, "blocked": 0}  #json element
0  #json timer value


No hay comentarios:

Publicar un comentario