明霞山资源网 Design By www.htccd.com

首先获得好友或者公众号的UserName

1. 获取好友UserName

#coding=utf8
import itchat
itchat.auto_login(hotReload=True)

#想给谁发信息,先查找到这个朋友,name后填微信备注即可,deepin测试成功
users = itchat.search_friends(name='')
#获取好友全部信息,返回一个列表,列表内是一个字典
print(users)
#获取`UserName`,用于发送消息
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. 获取公众号UserName

#coding=utf8
import itchat

itchat.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 itchat

itchat.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")

以上这篇Python利用itchat库向好友或者公众号发消息的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
Python,itchat,好友,公众号

明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。