準備工作:
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}
标簽:info,code,get,Python,itchat,二維碼,子產品,import