Python中的第三方模块(itchat)

准备工作:
pycharm导入第三方模块的包

1.ctrl+alt+s进入settings,选择Project下的Project Interpreter
在这里插入图片描述
2.点击右上角的加号,进入之后搜索qrcode,选择install
安装成功之后会提示
在这里插入图片描述
在这里插入图片描述
3.搜索itchat,同样install,安装成功之后esc退出,选择ok即可
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
练习1:扫描二维码后文件传输助手会一直发送hello

import itchat
itchat.auto_login()
while True:
    itchat.send('hello',toUserName='filehelper')

在这里插入图片描述
练习2:扫描二维码之后和会一直发送文件

import random
import time
import itchat
itchat.auto_login()
while True:
    itchat.send_file('/etc/passwd', toUserName='filehelper')
    time.sleep(random.randint(1,3))

在这里插入图片描述
练习3:统计微信好友中男性,女性还有其他的数量

import itchat
itchat.auto_login()
friends = itchat.get_friends()
info = {}
for friend in friends[1:]:
    if friend['Sex'] == 1:
        info['male'] = info.get('male',0) + 1
    elif friend['Sex'] == 2:
        info['female'] = info.get('female',0) + 1
    else:
        info['other'] = info.get('other',0) + 1
print(info)

##执行之后会生成一个二维码,扫描二维码,点击登陆即可在出现结果

Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as 孤岛
{'male': 68, 'female': 78, 'other': 10}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44224894/article/details/88957784