import json
res_list = {}
req = requests.get('https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=diseaseh5Shelf%27)
req_data = json.loads(req.text).get('data')
req_data = req_data.get('diseaseh5Shelf')
print('第2個接口json驗證通過')
lastupdatetime = req_data['lastUpdateTime']
chinatotal = req_data['chinaTotal']
chinaadd = req_data['chinaAdd']
areaTree = req_data['areaTree'][0]
res_list['lastUpdateTime'] = lastupdatetime
res_list['chinaTotal'] = chinatotal
res_list['chinaAdd'] = chinaadd
res_list['citydata'] = []
#for i_areaTree in areaTree['children']:
for i_areaTree_end in i_areaTree['children']:
city_name = i_areaTree_end['name']
if city_name in ['北海']:
print(city_name)
#if prov_name in ['北海']:
for i_areaTree_end in i_areaTree['children']:
i_city_data = {}
i_city_data['prov_name'] = prov_name
i_city_data['city_name'] = i_areaTree_end['name']
i_city_data['local_confirm_add'] = i_areaTree_end['today']['local_confirm_add']#新增本土
i_city_data['wzz_add'] = i_areaTree_end['today']['wzz_add']#新增無症狀
i_city_data['mediumRiskAreaNum'] = i_areaTree_end['total']['mediumRiskAreaNum']#中風險地區個數
i_city_data['highRiskAreaNum'] = i_areaTree_end['total']['highRiskAreaNum']#中風險地區個數
i_city_data['suspect'] = 0
i_city_data['dead'] = i_areaTree_end['total']['dead']
i_city_data['heal'] = i_areaTree_end['total']['heal']
i_city_data['grade'] = '' if (i_areaTree_end['total'].get('grade') is None) else
i_areaTree_end['total']['grade']
res_list['citydata'].append(i_city_data)
print(res_list)
![img](
的解答思路和嘗試過的方法