Python利用itchat庫向好友或者公眾號(hào)發(fā)消息的實(shí)例
首先獲得好友或者公眾號(hào)的UserName
1. 獲取好友UserName
#coding=utf8
import itchat
itchat.auto_login(hotReload=True)
#想給誰發(fā)信息,先查找到這個(gè)朋友,name后填微信備注即可,deepin測(cè)試成功
users = itchat.search_friends(name='')
#獲取好友全部信息,返回一個(gè)列表,列表內(nèi)是一個(gè)字典
print(users)
#獲取`UserName`,用于發(fā)送消息
userName = users[0]['UserName']
itcha.send("hello",toUserName = userName)
#coding=utf8 import itchat itchat.auto_login(hotReload=True) #獲取所有好友信息 account=itchat.get_friends() # #獲取自己的UserName userName = account[0]['UserName']
2. 獲取公眾號(hào)UserName
#coding=utf8
import itchat
itchat.auto_login(hotReload=True)
#返回完整的公眾號(hào)列表
mps = itchat.get_mps()
## 獲取名字中含有特定字符的公眾號(hào),也就是按公眾號(hào)名稱查找,返回值為一個(gè)字典的列表
mps = itchat.search_mps(name='CSDN')
print(mps)
#發(fā)送方法和上面一樣
userName = mps[0]['UserName']
itchat.send("hello",toUserName = userName)
3. 發(fā)送內(nèi)容代碼如下
#coding=utf8
import itchat
itchat.auto_login(hotReload=True)
#獲取通訊錄信息
account=itchat.get_friends()
# #獲取自己的UserName
userName = account[0]['UserName']
#獲取公眾號(hào)信息
# mps = itchat.get_mps()
# print(mps)
lines = []
#讀取txt文件
f = open("/home/numb/Desktop/aaa.txt")
lines = f.readlines()#讀取全部?jī)?nèi)容
#循環(huán)發(fā)送文本內(nèi)容
for i in range(90):
#UserName需要用上面獲取的自己修改
itchat.send(lines[i],toUserName='UserName')
print("Success")
以上這篇Python利用itchat庫向好友或者公眾號(hào)發(fā)消息的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python使用itchat庫實(shí)現(xiàn)微信機(jī)器人(好友聊天、群聊天)
- 使用Python微信庫itchat獲得好友和群組已撤回的消息
- Python微信庫:itchat的用法詳解
- python實(shí)現(xiàn)微信接口(itchat)詳細(xì)介紹
- Python利用itchat對(duì)微信中好友數(shù)據(jù)實(shí)現(xiàn)簡(jiǎn)單分析的方法
- 利用python微信庫itchat實(shí)現(xiàn)微信自動(dòng)回復(fù)功能
- python-itchat 統(tǒng)計(jì)微信群、好友數(shù)量,及原始消息數(shù)據(jù)的實(shí)例
相關(guān)文章
pytorch加載自己的圖像數(shù)據(jù)集實(shí)例
這篇文章主要介紹了pytorch加載自己的圖像數(shù)據(jù)集實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Python qrcode 生成一個(gè)二維碼的實(shí)例詳解
在本篇文章里小編給大家整理的是關(guān)于Python qrcode 生成一個(gè)二維碼的實(shí)例內(nèi)容,需要的朋友們可以學(xué)習(xí)參考下。2020-02-02
Python中交換兩個(gè)元素的實(shí)現(xiàn)方法
今天小編就為大家分享一篇Python中交換兩個(gè)元素的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06
用Python寫一個(gè)模擬qq聊天小程序的代碼實(shí)例
今天小編就為大家分享一篇關(guān)于用Python寫一個(gè)模擬qq聊天小程序的代碼實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03
Python人工智能實(shí)戰(zhàn)之以圖搜圖的實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了如何基于vgg網(wǎng)絡(luò)和Keras深度學(xué)習(xí)框架實(shí)現(xiàn)以圖搜圖功能。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下2022-05-05

