从HTTP响应获取JSON?

时间:2018-06-25 22:21:23

标签: python json

https://omniexplorer.info/address/3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL

https://i.imgur.com/DWHeELo.png

在imgur链接中,我想使用python获取JSON输出。
我通过在omniexplorer网站上单击F12进入网络,然后单击0,进入imgur页面。

如何使用python将以下输出作为JSON获取?

{
  "address": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
  "pages": 10, 
  "transactions": [
    {
      "amount": "250000000.00000000", 
      "block": 529186, 
      "blockhash": "0000000000000000001102a848ce2e5bfa6dd69f14eb9afac04dd39cb75f350e", 
      "blocktime": 1529935167, 
      "confirmations": 51, 
      "divisible": true, 
      "fee": "0.00046501", 
      "ismine": false, 
      "positioninblock": 534, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1NTMakcgVwQpMdGxRQnFKyb3G1FAJysSfz", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "bd9520b9aea701e9606ad8a8f4d6852d70f2013b12df19b6d58147038392354e", 
      "type": "Grant Property Tokens", 
      "type_int": 55, 
      "valid": true, 
      "version": 0
    }, 
    {
      "amount": "250000000.00000000", 
      "block": 523272, 
      "blockhash": "0000000000000000002e86cd0495daae675f2fbfa3f601dd2205e3d364f1705e", 
      "blocktime": 1526667641, 
      "confirmations": 5965, 
      "divisible": true, 
      "fee": "0.00046501", 
      "ismine": false, 
      "positioninblock": 256, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1NTMakcgVwQpMdGxRQnFKyb3G1FAJysSfz", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "23407cc132443fe5eff94d19ca016705623ca490c74d1a215a1026d801972263", 
      "type": "Grant Property Tokens", 
      "type_int": 55, 
      "valid": true, 
      "version": 0
    }, 
    {
      "amount": "100.00000000", 
      "block": 519883, 
      "blockhash": "0000000000000000001a226aea1237aa124c741d73e897cc8384f273578a682e", 
      "blocktime": 1524671109, 
      "confirmations": 9354, 
      "divisible": true, 
      "fee": "0.00026055", 
      "invalidreason": "Sender is frozen for the property", 
      "ismine": false, 
      "positioninblock": 1324, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "sendingaddress": "13K5cZHvDBR4Me39PLFS3JaPdaJocm8ygf", 
      "txid": "86b37baf4ce8935c4c892e9ce2577029951b072275e220ee1cd31e42c7b8a64b", 
      "type": "Simple Send", 
      "type_int": 0, 
      "valid": false, 
      "version": 0
    }, 
    {
      "amount": "300000000.00000000", 
      "block": 514409, 
      "blockhash": "00000000000000000009f9a46950063c7cfa0b9c4a70ce97a64a498186398d5e", 
      "blocktime": 1521571874, 
      "confirmations": 14828, 
      "divisible": true, 
      "fee": "0.00014453", 
      "ismine": false, 
      "positioninblock": 1598, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1NTMakcgVwQpMdGxRQnFKyb3G1FAJysSfz", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "f3efac4b6203248fc06e2788b61e732319a6e596768f5240680f944780ff84f4", 
      "type": "Grant Property Tokens", 
      "type_int": 55, 
      "valid": true, 
      "version": 0
    }, 
    {
      "block": 513109, 
      "blockhash": "0000000000000000003948c4093e0e7d99e9e03ac5f1e5b271a8a3a1e652f977", 
      "blocktime": 1520823390, 
      "confirmations": 16128, 
      "fee": "0.00015001", 
      "ismine": false, 
      "positioninblock": 222, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1B4dCsH6MC9XoZ6ob2nngvJesYEfNNtMQS", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "70be9bbbbd5de26b856d9cd3dfa5679f2badd10f03386bf26c0b99795608610f", 
      "type": "Freeze Property Tokens", 
      "type_int": 185, 
      "valid": true, 
      "version": 0
    }, 
    {
      "block": 513109, 
      "blockhash": "0000000000000000003948c4093e0e7d99e9e03ac5f1e5b271a8a3a1e652f977", 
      "blocktime": 1520823390, 
      "confirmations": 16128, 
      "fee": "0.00015001", 
      "ismine": false, 
      "positioninblock": 221, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1B6me5MvLP7Mu1yYXB8mbEVtsRsQkeYr6X", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "e084ad7005731284d9f1743671e753f4380c6945a960d43b22004a78a63cfedf", 
      "type": "Freeze Property Tokens", 
      "type_int": 185, 
      "valid": true, 
      "version": 0
    }, 
    {
      "block": 513109, 
      "blockhash": "0000000000000000003948c4093e0e7d99e9e03ac5f1e5b271a8a3a1e652f977", 
      "blocktime": 1520823390, 
      "confirmations": 16128, 
      "fee": "0.00015001", 
      "ismine": false, 
      "positioninblock": 220, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "13K5cZHvDBR4Me39PLFS3JaPdaJocm8ygf", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "a5e0e79d454d98fbc0fa2cb226c08dd717f4265faec7a1f5316f89e9c27712d2", 
      "type": "Freeze Property Tokens", 
      "type_int": 185, 
      "valid": true, 
      "version": 0
    }, 
    {
      "block": 513109, 
      "blockhash": "0000000000000000003948c4093e0e7d99e9e03ac5f1e5b271a8a3a1e652f977", 
      "blocktime": 1520823390, 
      "confirmations": 16128, 
      "fee": "0.00015001", 
      "ismine": false, 
      "positioninblock": 219, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "referenceaddress": "1PU73xR1fiRj1t3S44LtYiLqAr17tRcwfp", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "0a21a9102312489adfa6208d9d37f2572175f9e39882c3b441fa1b0a0aff6511", 
      "type": "Freeze Property Tokens", 
      "type_int": 185, 
      "valid": true, 
      "version": 0
    }, 
    {
      "amount": "1", 
      "block": 507793, 
      "blockhash": "0000000000000000003c8ca0a3edd5ab41de239ea26e282ad30e7f971fb4bcdb", 
      "blocktime": 1517841270, 
      "confirmations": 21444, 
      "divisible": false, 
      "fee": "0.00010000", 
      "ismine": false, 
      "positioninblock": 1137, 
      "propertyid": 321, 
      "propertyname": "Bitcoin Cash", 
      "referenceaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "sendingaddress": "1Pzz7q2mUqAgbBkTvitPYxuub8WST9iYb3", 
      "txid": "6ea43cdbfc463276812c97b78bd96bea5ab5c944a9a2e6e0632f5b097b247c76", 
      "type": "Simple Send", 
      "type_int": 0, 
      "valid": true, 
      "version": 0
    }, 
    {
      "amount": "30000000.00000000", 
      "block": 506983, 
      "blockhash": "000000000000000000064bf40b2625bda1df2746fb5a27cccb4e60e1a17b0454", 
      "blocktime": 1517412586, 
      "confirmations": 22254, 
      "divisible": true, 
      "fee": "0.00109885", 
      "ismine": false, 
      "positioninblock": 322, 
      "propertyid": 31, 
      "propertyname": "TetherUS", 
      "sendingaddress": "3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL", 
      "txid": "24db40680654b8b505fda3e96be722ca10f341a129c99260509eb5d84655f1f0", 
      "type": "Revoke Property Tokens", 
      "type_int": 56, 
      "valid": true, 
      "version": 0
    }
  ]
}

1 个答案:

答案 0 :(得分:3)

您可以右键单击0,然后将其复制为cURL,然后可以paste into this site

我将地址提取到一个变量中。安装requests库,该库具有json()输出功能

import requests

address = '3MbYQMMmSkC3AgWkj9FMo5LsPTW1zBTwXL'

headers = {
    'origin': 'https://omniexplorer.info',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9',
    'user-agent': 'python-requests',
    'content-type': 'application/x-www-form-urlencoded',
    'accept': '*/*',
    'referer': 'https://omniexplorer.info/address/{}'.format(address),
    'authority': 'api.omniexplorer.info',
}

data = [('addr', address)]

response = requests.post('https://api.omniexplorer.info/v1/transaction/address/0', headers=headers, data=data)

print(response.json())