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

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

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

Python中的第三方模块(itchat)
练习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))

Python中的第三方模块(itchat)
练习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}

Python中的第三方模块(itchat)
Python中的第三方模块(itchat)
Python中的第三方模块(itchat)
Python中的第三方模块(itchat)

相关文章:

  • 2021-09-24
  • 2021-12-29
  • 2021-06-01
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-02-06
  • 2021-06-17
猜你喜欢
  • 2021-08-05
  • 2021-09-13
  • 2021-06-27
  • 2022-01-05
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案