python json接口数据提取_python读取api接口json数据

#by 侯禹江

#2018、/0/27

import json

from urllib.request import Request, urlopen

#zb网站获取数据Api

url = "https://trans.bitkk.com/line/topall?area=&jsoncallback=jQuery191025699015513536727_1530079609291&_=1530079609293"

#包装头部

firefox_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}

#构建请求

request = Request( url, headers=firefox_headers )

html = urlopen( request )

#获取数据

data = html.read()

#转换成字符串

strs = str(data)

#截取字符串

print(len(strs))

strs_for_json = strs[44:]

strs_for_json= strs_for_json[:-2]

print(strs_for_json)

#转换成JSON

data = strs_for_json

datas = json.dumps(data)

#转换成字典数据

data_json = json.loads(data)

print(type(data_json))#

print(data_json['datas'][0]['market'],data_json['datas'][0]['sell1Price'])

print(len(data_json['datas']))

len = len(data_json['datas'])

#输出价格表

print("*****************************zb价格获取***************************************")

for i in range(0,len):

print("币种\市场类型:"+data_json['datas'][i]['market'], "^^^^^^^","实时价格:"+data_json['datas'][i]['sell1Price'],"^^^^^^^","24小时最高价格:"+data_json['datas'][i]['hightPrice'],"^^^^^^^","24小时最低价格:"+data_json['datas'][i]['lastPrice'])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值