分析微信好友列表信息(json)

在前面我们玩了好多静态的 HTML,但还有一些常见的动态数据,比如,商品的评论数据、实时的直播弹幕等,这些数据是会经常发生改变的,所以很多网站就会用到 Json 来传输这些数据。

Python JSON

可以用 json 模块,

1. 将 python 对象转化为 json是这样的 json.dumps()

2. 将json数据转化为python对象是这样的 json.loads()

微信好友列表

 登陆微信网页版(据说现在很多微信号不能等网页版了??)

很容易找到有一个请求,会返回所有好友的信息,比如我的 https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?r=1579169908913&seq=0&skey=@crypt_334af1c3_09cdad2bc5602306e76ec45783717d63

下载保存为txt,这是按json格式的。

下面只分析其中一个好友信息:

分析微信好友列表信息(json)
import jsonjsondata = ‘‘‘{ "Uin": 0, "UserName": "@c7205bf5d2b6aaaa9103ca74e4b27909e8d5aa2c9571273f0426671890c589fb", "NickName": "河广", "HeadImgUrl": "/cgi-bin/mmwebwx-bin/webwxgeticon?seq=710423455&username=@c7205bf5d2b6aaaa9103ca74e4b27909e8d5aa2c9571273f0426671890c589fb&skey=@crypt_334af1c3_09cdad2bc5602306e76ec45783717d63", "ContactFlag": 3, "MemberCount": 0, "MemberList": [], "RemarkName": "易杭", "HideInputBarFlag": 0, "Sex": 1, "Signature": "终不似,少年游", "VerifyFlag": 0, "OwnerUin": 0, "PYInitial": "HG", "PYQuanPin": "heguang", "RemarkPYInitial": "YH", "RemarkPYQuanPin": "yihang", "StarFriend": 0, "AppAccountFlag": 0, "Statues": 0, "AttrStatus": 102437, "Province": "湖南", "City": "娄底", "Alias": "", "SnsFlag": 257, "UniFriend": 0, "DisplayName": "", "ChatRoomId": 0, "KeyWord": "", "EncryChatRoomId": "", "IsOwner": 0}‘‘‘myfriend = json.loads(jsondata) print(myfriend[NickName])print(myfriend.get(NickName))

如果要分析好友列表,循环就可以了。

import jsonwith open(rcontact.txt,r, encoding = utf-8) as file_open: data = json.load(file_open) data = data[MemberList] print(len(data)) for line in data: print(line["NickName"])

 

 

参考链接:

1. 爸爸,他使坏,用动态的 Json 数据,我要怎么搞?

2. python 从TXT中解析json格式

相关文章