python统计自己微信好友并抓取信息
生活随笔
收集整理的這篇文章主要介紹了
python统计自己微信好友并抓取信息
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
前幾天統(tǒng)計自己好友性別,看看男女比例,發(fā)現(xiàn)竟然還有分類不是男女的,很好奇都是誰,所以空閑下來抓取所有好友看一下。
這邊使用了itchat庫,網(wǎng)上資料很多。不多說,直接上代碼
import itchat import re from xlwt import * # 登錄 itchat.login() # 獲取好友列表 friends = itchat.get_friends(update=True)[0:] file = Workbook(encoding = 'utf-8') #指定file以utf-8的格式打開 table = file.add_sheet('wx') table.write(0,0,'姓名') table.write(0,1,'昵稱') table.write(0,2,'備注') table.write(0,3,'性別') table.write(0,4,'簽名') table.write(0,5,'頭像')friends = itchat.get_friends(update=True)[0:] for key,i in enumerate(friends): # 獲取個性簽名signature = i["Signature"].strip().replace("span", "").replace("class", "").replace("emoji", "") # 正則匹配過濾掉emoji表情,例如emoji1f3c3等rep = re.compile("1f\d.+")signature = rep.sub("", signature)NickName = i["NickName"]UserName = i["UserName"]HeadImgUrl = i["HeadImgUrl"]RemarkName = i["RemarkName"]Sex = i["Sex"]table.write(key+1,0,NickName)table.write(key+1,1,UserName)table.write(key+1,2,RemarkName)table.write(key+1,3,Sex)table.write(key+1,4,signature)table.write(key+1,5,HeadImgUrl) file.save('wx.xlsx')friends = itchat.get_friends(update=True)[0:]獲取到微信的好友信息,然后拉取需要的數(shù)據(jù),我這邊是獲取的姓名,昵稱,備注,性別,簽名,頭像。并導入excel表格中
轉(zhuǎn)載于:https://www.cnblogs.com/zdzdbk/p/11002197.html
總結(jié)
以上是生活随笔為你收集整理的python统计自己微信好友并抓取信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度优先 广度优先
- 下一篇: Maven虐我千百遍,我待Maven如初