|
发表于 2019-5-1 19:20:12
|
显示全部楼层
- # coding: utf-8
- import requests
- from lxml import etree
- if __name__ == '__main__':
- jszd= { "comments": { "attachments": [],
- "comments": [],
- "create_time": 1556625481348,
- "ip": "",
- "comment_id": 150423347,
- "reply_count": 0,
- "content": "我想问一下他们有善心嘛",
- "ip_location": "广东省广州市",
- "reply_id": 0,
- "passport":
- {
- "img_url": "https://sucimg.itc.cn/avatarimg/296670289_1444181118790",
- "user_id": 10115405,
- "nickname": "鱼可以飞么"
- },
- "user_id": 10115405,
- "from": "",
- "support_count": 0,
- "status": 1
- },
- "aaa":{
- "attachments": [],
- "comments": [],
- "create_time": 1556625475042,
- "ip": "",
- "comment_id": 150423360,
- "reply_count": 0,
- "content": "宇智波鼬的神器",
- "ip_location": "西藏自治区拉萨市",
- "reply_id": 0,
- "passport":
- {
- "img_url": "https://edc3f09a7c333.cdn.sohucs.com/s_mini/pic/2018/04/02/1.png",
- "user_id": 10115964,
- "nickname": "想个名咋这么难"
- },
- "user_id": 10115964,
- "from": "",
- "support_count": 0,
- "status": 1
- } }
- newlst=[]
- for x in jszd:
- for key in jszd[x].keys():
- tmp={}
- if key=="passport":
- tmp["user_id"]=jszd[x][key]["user_id"]
- tmp["nick_name"]=jszd[x][key]["nickname"]
- newlst.append(tmp)
- print(newlst)
复制代码
e:\>python ex16.py
[{'user_id': 10115405, 'nick_name': '鱼可以飞么'}, {'user_id': 10115964, 'nick_name': '想个名咋这么难'}] |
|