请教一个问题:在 python 中用 itchat 抓取群成员信息时,有一个群的信息有时抓得到有时抓不到,其他群都正常。
这是什么原因?
代码如下(主体代码是基于别人的做了小修改):
#!/usr/bin/env python # coding: utf-8 # In[1]: import itchat from itchat.content import TEXT from itchat.content import * import sys import os import socket import time import pandas as pd import re import datetime # In[2]: itchat.auto_login(hotReload=True) friends = itchat.get_friends(update=True)[0:] # In[3]: if socket.gethostname()=='xxxx': root=r'C:\Users\xxxx' else: root=r'E:\OneDrive - xxx' # In[4]: roomslist = [] def getroom_message(n): #获取群的 username,对群成员进行分析需要用到 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 RoomList = itchat.search_chatrooms(name=n) if RoomList is None: pass #print("{0} group is not found!".format(name)) else: # print('取得:',RoomList[0]['UserName']) return RoomList[0]['UserName'] def getchatrooms(): #获取群聊列表 roomslist = itchat.get_chatrooms() #print('列表',roomslist) return roomslist # In[5]: for i in getchatrooms(): roomslist.append(i['NickName']) # In[6]: data=[] for n in roomslist: ChatRoom = itchat.update_chatroom(getroom_message(n), detailedMember=True) for i in ChatRoom['MemberList']: data.append({'群名称':ChatRoom['NickName'], '省份':i['Province'], '用户名':i['NickName'], 'ID':i['UserName'], '性别':i['Sex']}) # In[7]: df=pd.DataFrame(data) df.to_csv((root+'\jupyter\群数据{}-{}-{}.csv').format(time.localtime().tm_year,time.localtime().tm_mon,time.localtime().tm_mday))
1
qingyuan0o0 2019-11-08 10:49:35 +08:00
itchat 居然还没坏啊
|
2
ywanght OP 已解决,关闭。
|