Python利用itchat库向好友或者公众号发消息
生活随笔
收集整理的這篇文章主要介紹了
Python利用itchat库向好友或者公众号发消息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先獲得好友或者公眾號的UserName
1.獲取好友UserName
2.獲取公眾號UserName
#coding=utf8 import itchatitchat.auto_login(hotReload=True) #返回完整的公眾號列表 mps = itchat.get_mps() ## 獲取名字中含有特定字符的公眾號,也就是按公眾號名稱查找,返回值為一個字典的列表 mps = itchat.search_mps(name='CSDN') print(mps) #發送方法和上面一樣 userName = mps[0]['UserName'] itchat.send("hello",toUserName = userName)3.發送內容代碼如下
#coding=utf8 import itchatitchat.auto_login(hotReload=True) #獲取通訊錄信息 account=itchat.get_friends() # #獲取自己的UserName userName = account[0]['UserName'] #獲取公眾號信息 # mps = itchat.get_mps() # print(mps) lines = [] #讀取txt文件 f = open("/home/numb/Desktop/aaa.txt") lines = f.readlines()#讀取全部內容 #循環發送文本內容 for i in range(90): #UserName需要用上面獲取的自己修改itchat.send(lines[i],toUserName='UserName') print("Success")參考:http://blog.csdn.net/th_num/article/details/55657453
總結
以上是生活随笔為你收集整理的Python利用itchat库向好友或者公众号发消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python-爬取中国天气网天气并通过邮
- 下一篇: deepin--更改最低亮度