【发布时间】:2019-04-05 22:14:18
【问题描述】:
我是 python 新手。我尝试从 api 读取一些数据,但在第二个 url 中有问题,我不知道当我有更多数据时如何解析 api。第一个 URL 只有一个“NAME”,第二个有多个 NAMES.... 我如何从第二个网址打印所有名称... 谢谢...
import os
from urllib import urlopen
import json
url = urlopen('https://www.coincalculators.io/api.aspx?name=ethereum&hashrate=420000000&power=0&poolfee=1&powercost=0&difficultytime=0').read()
data= json.loads(url)
name = data["name"] # OK
print name
rewardsInMonth = data["rewardsInMonth"] # OK
print rewardsInMonth
#url with more names
url2 = urlopen('https://www.coincalculators.io/api/allcoins.aspx?hashrate=420000000&power=0&powercost=0&difficultytime=0&algorithm=Ethash').read()
data2= json.loads(url2)
name2 = data2["name"] # OK
print name2
我看到第二个网址中有一个方括号,这对我来说是个问题。
【问题讨论】:
-
你用的是什么版本的 Python?