2018别样跨年|今晚让Python陪你,简单的机器人聊天
2017-12-31 21:54
204 查看
安装:
QQ:
pip install qqbot
微信:
pipi install itchat
1.选择
from qqbot import _bot as bot
bot.Login(['-q','QQ号码'])
friends= bot.List('buddy','xxx')
for friend in friends:
print (friend.name)
bot.SendTo(friend,'Hello%s~xxxxxxxx'%(friend.name))
首先我们登录SmartQQ:
from qqbot import _bot as botbot.Login(['-q', 'XXXX'])
其中,XXXX输入你自己的QQ号。如果第一次登录,会跳出来一个二维码让你扫,扫一下即可,之后你的账号信息会被保存下来,下次再登录就可以直接调用了。
然后我们选择好友:
friends = bot.List('buddy')
如果想随机抽取一部分,比如10个, 则:
friends = random.sample(friends,10)
如果想定点发送,则:
friends = bot.List('buddy', 'XXX')
XXX里面放好友的备注。
下面我们来给随机(或者假装随机,此处应该划重点)的好友发消息:
for friend in friends:
print(friend.name)
bot.SendTo(friend,'Hello%s~这是一条来自Python机器人的消息~恭喜你被机器人抽中成为幸运的十个人之一~'%(friend.name))
2.微信
微信的操作非常类似,不过账号信息只能保存一阵子,所以需要经常扫码,如果扫码过于频繁,就会登录不上了……别问我怎么知道的,我刚想给好久没有勾搭的女神发消息呢……就崩溃了……
首先还是登录:
import
itchatitchat.auto_login(True)
True参数是指保存一阵子登录信息,如果不加则不保存。
获取好友列表和随机抽取:
friends
=
itchat.get_friends()
随机抽取10位好友:
import random
friends = random.sample(friends, 10)
或者假装随机抽取好友:
friends = itchat.search_friends(name='XXX')
XXX 填上备注/微信号/昵称。
发送消息:
import time
for friend in friends:
print(friend)
itchat.send('%s你好~这是一条来自Python机器人的问候~我随机抽取了十个人发送了这条消息~'%(friend['DisplayName']), friend['UserName'])
time.sleep(0.5)
为了防止发送过快被封,加了一个小小的暂停。
QQ:
pip install qqbot
微信:
pipi install itchat
1.选择
from qqbot import _bot as bot
bot.Login(['-q','QQ号码'])
friends= bot.List('buddy','xxx')
for friend in friends:
print (friend.name)
bot.SendTo(friend,'Hello%s~xxxxxxxx'%(friend.name))
首先我们登录SmartQQ:
from qqbot import _bot as botbot.Login(['-q', 'XXXX'])
其中,XXXX输入你自己的QQ号。如果第一次登录,会跳出来一个二维码让你扫,扫一下即可,之后你的账号信息会被保存下来,下次再登录就可以直接调用了。
然后我们选择好友:
friends = bot.List('buddy')
如果想随机抽取一部分,比如10个, 则:
friends = random.sample(friends,10)
如果想定点发送,则:
friends = bot.List('buddy', 'XXX')
XXX里面放好友的备注。
下面我们来给随机(或者假装随机,此处应该划重点)的好友发消息:
for friend in friends:
print(friend.name)
bot.SendTo(friend,'Hello%s~这是一条来自Python机器人的消息~恭喜你被机器人抽中成为幸运的十个人之一~'%(friend.name))
2.微信
微信的操作非常类似,不过账号信息只能保存一阵子,所以需要经常扫码,如果扫码过于频繁,就会登录不上了……别问我怎么知道的,我刚想给好久没有勾搭的女神发消息呢……就崩溃了……
首先还是登录:
import
itchatitchat.auto_login(True)
True参数是指保存一阵子登录信息,如果不加则不保存。
获取好友列表和随机抽取:
friends
=
itchat.get_friends()
随机抽取10位好友:
import random
friends = random.sample(friends, 10)
或者假装随机抽取好友:
friends = itchat.search_friends(name='XXX')
XXX 填上备注/微信号/昵称。
发送消息:
import time
for friend in friends:
print(friend)
itchat.send('%s你好~这是一条来自Python机器人的问候~我随机抽取了十个人发送了这条消息~'%(friend['DisplayName']), friend['UserName'])
time.sleep(0.5)
为了防止发送过快被封,加了一个小小的暂停。
相关文章推荐
- Python 实现简单的局域网聊天
- python socket编程 实现简单p2p聊天程序
- Python基于TCP实现会聊天的小机器人功能示例
- python利用TCP实现会聊天的小机器人
- python的tkinter布局之简单的聊天窗口实现方法
- webqq2协议分析和qq聊天机器人简单实现
- Python 超简单的聊天程序
- 用python写1个简单的聊天服务器5-DB层处理
- 用python搭建简单的聊天客户及服务端
- Python socket 实现简单的server-client聊天
- 用python写1个简单的聊天服务器-项目启动原因
- 用python写1个简单的聊天服务器7-业务处理
- 自己动手开发智能聊天机器人完全指南(附python完整源码)
- 用python实现的一个自动聊天的机器人
- 微信 聊天 机器人 python itchat
- 【C#学习】聊天机器人,网络数据的简单应用
- itchat 学习-用python实现聊天机器人
- 用python写1个简单的聊天服务器6-用户模型
- Python 超简单的聊天程序
- 简单实现python聊天程序