zoukankan      html  css  js  c++  java
  • python统计自己微信好友并抓取信息

    前几天统计自己好友性别,看看男女比例,发现竟然还有分类不是男女的,很好奇都是谁,所以空闲下来抓取所有好友看一下。

    这边使用了itchat库,网上资料很多。不多说,直接上代码

    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("1fd.+")
        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:]获取到微信的好友信息,然后拉取需要的数据,我这边是获取的姓名,昵称,备注,性别,签名,头像。并导入excel表格中

  • 相关阅读:
    没有什么,开发ASP.NET时随便写写,想到什么写什么
    MS SQL Server带有时间的记录怎样查询
    给RadioButtonList绑定Selected的值
    在GridView控件内文本框实现TextChanged事件
    MS SQL Server递归查询
    ASP.NET MVC使用jQuery无刷新上传
    MySQL 慢查询操作梳理
    ubuntu系统下防火墙简单使用
    crontab日常使用梳理
    ubuntu下nginx+php5的部署
  • 原文地址:https://www.cnblogs.com/zdzdbk/p/11002197.html
Copyright © 2011-2022 走看看