python Statistical own micro-letter friends and grab information

A few days ago a friend of gender statistics themselves, take a look at the proportion of men and women, to find out who we still have other classifications, are very curious, so grab idle down all your friends to see it.

Use the itchat library here, a lot of information online. Not much to say, directly on the code

Import itchat
 Import Re
 from xlwt Import *
 # Login 
itchat.login ()
 # get a buddy list 
Friends = itchat.get_friends (Update = True) [0:] 
file = Workbook (encoding = ' utf-8 ' )
 # specify the file to utf -8 open format 
Table file.add_sheet = ( ' WX ' ) 
table.write (0,0, ' name ' ) 
table.write (0, . 1, ' nickname ' ) 
table.write (0, 2, ' Remarks ' )
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" , " " )
 # Regular expression matching emoji filtered off, like e.g. emoji1f3c3 
    REP = the re.compile ( " 1F \ D. + " ) 
    Signature = rep.sub ( " " , Signature) 
    the NickName = I [ " the 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:] friends to get information about micro-letter, then pulling the data needed, I am here is to get the name, nickname, notes, gender, signature, avatar. And import the excel spreadsheet

Guess you like

Origin www.cnblogs.com/zdzdbk/p/11002197.html
Recommended