利用python檢視微信朋友圈好友的分佈情況——原始碼
阿新 • • 發佈:2018-12-19
方法:
1.安裝wxpy
2.執行程式碼
3.微信掃碼,成功後關閉二維碼就可看見了
from wxpy import * #建立網路機器人(bot取自robot),cache_path用於生成快取,避免每次執行都要登入二維碼 bot=Bot(cache_path=True) #bot.friends()用於獲取好友物件, bot.groups()用於獲取群聊物件 bot.mps()用於獲取微信公眾號. friends_stat=bot.friends().stats() #每個元素都是一個二維列表,分別儲存地區和人數資訊. friend_loc=[] for province,count in friends_stat["province"].items(): if province !="": friend_loc.append([province,count]) #對人數進行倒序排列 friend_loc.sort(key=lambda x:x[1],reverse=True) #列印前十個地區,及對應的人數 for item in friend_loc[:10]: print (item)