如何通过wxpy库实现微信自动发送消息功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计547个文字,预计阅读时间需要3分钟。
思路整理:
1.访问心灵鸡汤网页,使用Python获取心灵鸡汤内容。
2.登录微信,找到需要发送的朋友。
3.发送获取到的内容给朋友。
具体步骤:
1.获取心灵鸡汤内容:
- 使用Python请求心灵鸡汤网页。 - 解析网页内容,提取第一条心灵鸡汤。2. 登录微信: - 使用微信API登录。
3. 发送内容: - 找到需要发送的朋友。 - 发送提取的心灵鸡汤内容给朋友。
思路整理:1、进入心灵鸡汤网页,使用python获取心灵鸡汤内容
2、登陆微信,找到需要发送的朋友
3、发送获取的内容
1、获取心灵鸡汤的内容
如下图,获取第一条鸡汤
实现如下:
2、登陆微信,搜索朋友,进行发送
import requests import wxpy from bs4 import BeautifulSoup # 微信网页登陆 bot = wxpy.Bot(console_qr=2,cache_path='botoo.pkl') # 获取心灵鸡汤中的最新内容,可以参考其他爬虫随便查看怎么爬虫 def get_msg(): url = 'www.59xihuan.cn/index_1.html' h = requests.get(url) html = h.text news_bf = BeautifulSoup(html,"html.parser") msg = news_bf.find('div', class_='pic_text1') news = msg.text # print(msg) # print(news) return news # 给朋友发送消息 def send_msg(): try: # 添加朋友微信昵称 friend = bot.friends().search(u'xxxxx')[0] friend.send(get_msg()) 29 except:pass if __name__ == '__main__': send_msg()
其他发送类型格式:
- 发送文本消息:friend.send('文本消息')
- 发送图片消息:friend.send_image('图片消息.jpg')
- 发送视频消息:friend.send_video('视频消息.mov')
- 发送文件消息:friend.send_file('文件消息.zip')
- 以动态的方式发送图片:friend.send('@img@图片消息.jpg')
朋友收到的消息:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计547个文字,预计阅读时间需要3分钟。
思路整理:
1.访问心灵鸡汤网页,使用Python获取心灵鸡汤内容。
2.登录微信,找到需要发送的朋友。
3.发送获取到的内容给朋友。
具体步骤:
1.获取心灵鸡汤内容:
- 使用Python请求心灵鸡汤网页。 - 解析网页内容,提取第一条心灵鸡汤。2. 登录微信: - 使用微信API登录。
3. 发送内容: - 找到需要发送的朋友。 - 发送提取的心灵鸡汤内容给朋友。
思路整理:1、进入心灵鸡汤网页,使用python获取心灵鸡汤内容
2、登陆微信,找到需要发送的朋友
3、发送获取的内容
1、获取心灵鸡汤的内容
如下图,获取第一条鸡汤
实现如下:
2、登陆微信,搜索朋友,进行发送
import requests import wxpy from bs4 import BeautifulSoup # 微信网页登陆 bot = wxpy.Bot(console_qr=2,cache_path='botoo.pkl') # 获取心灵鸡汤中的最新内容,可以参考其他爬虫随便查看怎么爬虫 def get_msg(): url = 'www.59xihuan.cn/index_1.html' h = requests.get(url) html = h.text news_bf = BeautifulSoup(html,"html.parser") msg = news_bf.find('div', class_='pic_text1') news = msg.text # print(msg) # print(news) return news # 给朋友发送消息 def send_msg(): try: # 添加朋友微信昵称 friend = bot.friends().search(u'xxxxx')[0] friend.send(get_msg()) 29 except:pass if __name__ == '__main__': send_msg()
其他发送类型格式:
- 发送文本消息:friend.send('文本消息')
- 发送图片消息:friend.send_image('图片消息.jpg')
- 发送视频消息:friend.send_video('视频消息.mov')
- 发送文件消息:friend.send_file('文件消息.zip')
- 以动态的方式发送图片:friend.send('@img@图片消息.jpg')
朋友收到的消息:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

