日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python利用itchat库向好友或者公众号发消息

發(fā)布時(shí)間:2025/3/21 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python利用itchat库向好友或者公众号发消息 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先獲得好友或者公眾號(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 itchatitchat.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 itchatitchat.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")

參考:http://blog.csdn.net/th_num/article/details/55657453

總結(jié)

以上是生活随笔為你收集整理的Python利用itchat库向好友或者公众号发消息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。