Python 解析urlib请求

Python 解析urlib请求,python,urllib,Python,Urllib,我从代码中获得了以下巨大的输出:urllib.request.urlopen(“https://api...)读取() 这看起来像一个JSON对象,但它是一个字节对象。我正在调查整个事件的数据。我不知道如何解析所有这些嵌套字典。任何帮助都将不胜感激。我想提取位于端点附近的值112242287903649 b'{"address":"0x4264422fa4c1e60c2ee10d19549c0775fe544d7c","ETH":{&q

我从代码中获得了以下巨大的输出:
urllib.request.urlopen(“https://api...)读取()

这看起来像一个JSON对象,但它是一个字节对象。我正在调查整个事件的数据。我不知道如何解析所有这些嵌套字典。任何帮助都将不胜感激。我想提取位于端点附近的值112242287903649

b'{"address":"0x4264422fa4c1e60c2ee10d19549c0775fe544d7c","ETH":{"balance":39234.92760140797,"price":{"rate":406.0918669863694,"diff":3.33,"diff7d":7.19,"ts":1603860182,"marketCapUsd":45964513524.05101,"availableSupply":113187476.1865,"volume24h":14765115042.093159,"diff30d":14.028844201369225}},"countTxs":7,"tokens":[{"tokenInfo":{"address":"0x0d4b4da5fb1a7d55e85f8e22f728701ceb6e44c9","name":"DigiMax","decimals":"18","symbol":"DGMT","totalSupply":"1000000000000000000000000000","owner":"0x","lastUpdated":1603831313,"issuancesCount":0,"holdersCount":1042,"description":"DigiMax (DGMT) is a de-centralized Currency on ETHEREUM NETWORK. It is trustless, non-custodial, Layer-2 scaling solution for transferring value on Ethereum. It is Open Source. Community oriented and powered to maximize the power of the blockchain technology","website":"https://digimaxtoken.io/","twitter":"DigiMax_DGMT","image":"/images/DGMT0d4b4da5.png","telegram":"https://t.me/DigiMaxToken","reddit":"DigiMax_DGMT","coingecko":"digimax","price":{"rate":1.218303675e-5,"diff":3.55,"diff7d":-87.33,"ts":1603860187,"marketCapUsd":0,"availableSupply":0,"volume24h":0.36549128,"diff30d":-99.95948266499424,"currency":"USD"}},"balance":3.9e+19,"totalIn":0,"totalOut":0},{"tokenInfo":{"address":"0x28cb7e841ee97947a86b06fa4090c8451f64c0be","name":"YF Link","decimals":"18","symbol":"YFL","totalSupply":"52000000000000000000000","owner":"0x","lastUpdated":1603851830,"issuancesCount":0,"holdersCount":5164,"image":"/images/YFL28cb7e84.png","website":"https://yflink.io/","telegram":"https://t.me/YFLinkGroup","twitter":"YFLinkio","coingecko":"yflink","price":{"rate":411.62315709142763,"diff":2.44,"diff7d":22.67,"ts":1603860243,"marketCapUsd":20628385.985420085,"availableSupply":50114.73633112,"volume24h":673808.77973096,"diff30d":-9.745291974110742,"currency":"USD"},"publicTags":["Yield Farming","Yearn","Governance"]},"balance":69000000000000,"totalIn":0,"totalOut":0},{"tokenInfo":{"address":"0x618e75ac90b12c6049ba3b27f5d5f8651b0037f6","name":"QASH","decimals":"6","symbol":"QASH","totalSupply":"1000000000000000","owner":"0x9fa8a9cd0bd7cbfc503513bc94cd3b3a9ca90e35","lastUpdated":1603818056,"issuancesCount":0,"holdersCount":13087,"website":"https://liquid.plus/","facebook":"LiquidGlobal","telegram":"https://t.me/QUOINENews","twitter":"Liquid_Global","image":"/images/QASH618e75ac.jpeg","reddit":"liquid","coingecko":"qash","ethTransfersCount":2,"price":{"rate":0.03783789848158,"diff":2.83,"diff7d":0.05,"ts":1603860243,"marketCapUsd":13243264.468553,"availableSupply":350000000,"volume24h":170565.95092274,"diff30d":-5.421371004476654,"currency":"USD"},"publicTags":["Exchange"]},"balance":112242287903649,"totalIn":0,"totalOut":0},{"tokenInfo":{"address":"0x9f7229af0c4b9740e207ea283b9094983f78ba04","decimals":"18","name":"Tadpole","owner":"0x","symbol":"TAD","totalSupply":"1000000000000000000000000","lastUpdated":1603859098,"issuancesCount":0,"holdersCount":597,"price":false},"balance":100000000000000,"totalIn":0,"totalOut":0}]}'

内置的
json
模块完全能够解析字节字符串-

导入json
response=urllib.request.urlopen(“https://api/endpoint)改为
jsondat=json.load(响应)
现在,您可以随意使用
jsondat
,并提取所需的嵌套属性

请注意,您也可以使用
请求
模块,尽管在本例中您完全不必这样做,但可以更简单地实现这一点-

导入请求
jsondat=requests.get(“https://api/endpointjson()
对给定的字节字符串执行
json.loads
-

{'address':'0x4264422fa4c1e60c2ee10d19549c0775fe544d7c',
"ETH":{"余额":39234.92760140797,,
价格:{'rate':406.0918669863694,
“差异”:3.33,
“diff7d”:7.19,
‘ts’:1603860182,
“市场资本美元”:45964513524.05101,
“可用供应”:113187476.1865,
“卷24H”:14765115042.093159,
'diff30d':14.028844201369225},
“countTxs”:7,
'tokens':[{'tokenInfo':{'address':'0x0d4b4da5fb1a7d55e85f8e22f728701ceb6e44c9',
'name':'DigiMax',
‘小数’:‘18’,
“符号”:“DGMT”,
“总供应量”:“10000000000000000000”,
“所有者”:“0x”,
“最新更新”:1603831313,
“IssuanceScont”:0,
“持有者计数”:1042,
“描述”:“DigiMax(DGMT)是以太坊网络上的一种非集中式货币。它是一种不受信任、非托管的第二层扩展解决方案,用于在以太坊上转移价值。它是开源的。面向社区,以最大化区块链技术的力量为动力”,
“网站”:https://digimaxtoken.io/',
“推特”:“DigiMax_DGMT”,
“image”:“/images/DGMT0d4b4da5.png”,
“电报”:https://t.me/DigiMaxToken',
“reddit”:“DigiMax_DGMT”,
“Coincecko”:“digimax”,
‘价格’:{‘费率’:1.218303675e-05,
“差异”:3.55,
‘diff7d’:-87.33,
‘ts’:1603860187,
“marketCapUsd”:0,
“availableSupply”:0,
“卷24H”:0.36549128,
‘diff30d’:-99.95948266499424,
“货币”:“美元”},
“余额”:3.9e+19,
“totalIn”:0,
“totalOut”:0},
{'tokenInfo':{'address':'0x28cb7e841ee97947a86b06fa4090c8451f64c0be',
'name':'YF Link',
‘小数’:‘18’,
“符号”:“YFL”,
“总供应量”:“5200000000000000”,
“所有者”:“0x”,
“最新更新”:1603851830,
“IssuanceScont”:0,
'holdersCount':5164,
“image”:“/images/YFL28cb7e84.png”,
“网站”:https://yflink.io/',
“电报”:https://t.me/YFLinkGroup',
“twitter”:“YFLinkio”,
“coincecko”:“yflink”,
价格:{'rate':411.62315709142763,
“差异”:2.44,
“diff7d”:22.67,
‘ts’:1603860243,
“市场资本美元”:20628385.985420085,
“可用供应”:50114.73633112,
“卷24H”:673808.77973096,
‘diff30d’:-9.745291974110742,
“货币”:“美元”},
“publicTags”:[“产量农业”、“渴望”、“治理”],
“余额”:6900000000000,
“totalIn”:0,
“totalOut”:0},
{'tokenInfo':{'address':'0x618e75ac90b12c6049ba3b27f5d5f8651b0037f6',
'name':'QASH',
‘小数’:‘6’,
“符号”:“卡什”,
“总供应量”:“10000000000000”,
“所有者”:“0x9fa8a9cd0bd7cbfc503513bc94cd3b3a9ca90e35”,
“最新更新”:1603818056,
“IssuanceScont”:0,
“持有人计数”:13087,
“网站”:https://liquid.plus/',
“facebook”:“LiquidGlobal”,
“电报”:https://t.me/QUOINENews',
“twitter”:“Liquid_Global”,
“image”:“/images/QASH618e75ac.jpeg”,
“reddit”:“液体”,
“Coincecko”:“qash”,
“ethTransfersCount”:2,
‘价格’:{‘汇率’:0.03783789848158,
“差异”:2.83,
“diff7d”:0.05,
‘ts’:1603860243,
“marketCapUsd”:13243264.468553,
“可用供应”:350000000,
“卷24H”:170565.95092274,
‘diff30d’:-5.421371004476654,
“货币”:“美元”},
'publicTags':['Exchange']},
“余额”:112242287903649,
“totalIn”:0,
“totalOut”:0},
{'tokenInfo':{'address':'0x9f7229af0c4b9740e207ea283b9094983f78ba04',
‘小数’:‘18’,
‘名字’:‘蝌蚪’,
“所有者”:“0x”,
'symbol':'TAD',
“totalSupply”:“10000000000000000000000”,
“最新更新”:1603859098,
“IssuanceScont”:0,
“holdersCount”:597,
'price':False},
“余额”:1000000000000,
“totalIn”:0,
“totalOut”:0}]}

您可以使用python中的
json
库将其转换为字典
json.load(您的_字符串)
使用
json
模块加载它并访问您想要的值。另外,使用
请求
可能更方便(即使用
Response.json()
方法)。