初学,最笨的转化
代码上来~~
import Model
url3 ="http://www.kuaidi.com/index-ajaxselectcourierinfo-1202247993797-yunda.html"
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0"
}
s = requests.session()
r = s.get(url3,headers=headers,verify=True)
result = r.json()
data = result["data"]# 获取data里面内容
print data
allArr = []
for dicin data:
Model.model["context"] = dic["context"]
Model.model["time"] = dic["time"]
allArr.append(Model)
print len(allArr)
Model = allArr[0]
print "时间:",Model.model["time"],Model.model["context"]
上面的代码很好理解,就是通过for in遍历data的json数据,这里data是一个数组,数组中有多个dict;把dict中参数值赋值到model模型属性中,然后把model存到数组allArr中
Model中的代码超级简单
# -*- coding: utf-8 -*-
'''
Created on 2018年3月15日
@author: YC
'''
model={
"context":'',
"time":''
}