首先獲得好友或者公眾號的UserName #coding=utf8import itchatitchat.auto_login(hotReload=True)#想給誰發(fā)信息,,先查找到這個朋友,name后填微信備注即可,deepin測試成功users = itchat.search_friends(name='')#獲取好友全部信息,返回一個列表,列表內(nèi)是一個字典print(users)#獲取`UserName`,用于發(fā)送消息userName = users[0]['UserName']itcha.send('hello',toUserName = userName)
#coding=utf8import itchatitchat.auto_login(hotReload=True) #獲取所有好友信息account=itchat.get_friends()# #獲取自己的UserNameuserName = account[0]['UserName']
2.獲取公眾號UserName #coding=utf8import itchatitchat.auto_login(hotReload=True) #返回完整的公眾號列表mps = itchat.get_mps()## 獲取名字中含有特定字符的公眾號,,也就是按公眾號名稱查找,返回值為一個字典的列表mps = itchat.search_mps(name='CSDN')print(mps)#發(fā)送方法和上面一樣userName = mps[0]['UserName']itchat.send('hello',toUserName = userName)
3.發(fā)送內(nèi)容代碼如下 #coding=utf8import itchatitchat.auto_login(hotReload=True) #獲取通訊錄信息account=itchat.get_friends()# #獲取自己的UserNameuserName = account[0]['UserName']#獲取公眾號信息# mps = itchat.get_mps()# print(mps)lines = []#讀取txt文件f = open('/home/numb/Desktop/aaa.txt') lines = f.readlines()#讀取全部內(nèi)容 #循環(huán)發(fā)送文本內(nèi)容for i in range(90): #UserName需要用上面獲取的自己修改 itchat.send(lines[i],toUserName='UserName') print('Success')
|
|