快要过节了,懒得自己一个个手工去发祝福短信,提前写好了python脚本,等到了那天再试试吧,群发脚本如下,还需要测试下
我们需要先安装wxpy模块
#!/usr/bin/python3
#coding:utf-8
'''节日群发信息'''
from wxpy import Bot
import random
import re
#发送者
sender = "苏老"
#匹配规则
reg = "<Friend: (.*?)>"
src = re.compile(reg)
#祝福短信列表
msg = ["%s 祝你圣诞快乐, %s 敬上", "%s 祝你元旦快乐, %s 敬上", "%s 祝你新春快乐, %s 敬上"]
#获取祝福短信数量,从0开始所以减一
length = len(msg) - 1
bot = Bot()
friends = bot.friends()
#print(friends)
#获取的好友是个列表,第一个是自己,我们通过切片获取第二个到最后一个好友
for f in friends[1:]:
try:
#筛选出微信好友昵称
recivers = re.findall(src, f)
#随机获取祝福短信
f.send(msg[random.randint(0, length)] % (recivers[0][0], sender))
print("给 %s 发送的节日祝福已成功!" % recivers[0][0])
except:
print("发送失败,可能 %s 不是你的好友!" % recivers[0][0])
#将不是好友记录下来
with open('failed.log', 'w') as g:
g.write("%s no friend ! \n" % recivers[0][0])msg列表里面就是你的祝福语,每组用英文逗号相隔,注意多复制几组进去,这样通过随机方法取出的每次都不一样,这样让别人认为你又认真编辑短信发送给每个人
下面是我打印的微信好友

- 标签
- python
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://sulao.cn/post/601
评论列表