Python实现微信每日一句自动发送功能详解

白榆
白榆
发布时间:2026-10-13 | 5人浏览过
原创

本文介绍如何利用Python的wxpy库实现微信每日一句的自动发送功能。通过调用开放接口获取内容,并结合定时任务向指定好友或群组发送消息。文中提供了完整的代码示例,并提示了高频发送可能导致的账号限制风险及解决方案。

Python微信自动发送功能概述

本文分享了一个使用Python实现微信每日一句自动发送功能的完整代码示例,供读者参考学习。

该实现参考了相关技术博客中关于使用Python实现微信每日给特定好友发送晚安问候的方法。

核心代码实现与解析

具体实现代码如下:


# -*- coding: utf-8 -*-
'''
这是一个用来测试微信自动发送消息的demo
恩,主要就是用到了一个微信库--wxpy
安装很简单 pip install wxpy
下面就开始吧
主要就两个函数
1、getNews();用以获取信息
2、sendNews();用以发送信息

我这里发送消息用的是for循环本意是群发,但是!但是!但是!程序发的太快会被微信禁掉,大概40个人左右就会被禁,以后可以试试sleep一下。

另外vscode中自定义python编译器:
Ctrl+shift+p, 选择 python: Select Interpreter
'''


from __future__ import unicode_literals
from wxpy import *
import requests
from threading import Timer

itchat = Bot(console_qr=2,cache_path="botoo.pkl")
def getNews():
 url = "http://open.iciba.com/dsapi/"
 r = requests.get(url)
 content = r.json()['content']
 note = r.json()['note']
 return content, note

def sendNews():
 try:
  #这里是备注
  friend = itchat.friends().search(name = u'xxx')

  content = getNews()
  print(content)
  message1 = str(content[0])
  message2 = str(content[1])
  message3 = "xxx"
  print(friend)

  for index,item in enumerate(friend):


   print("发送给 "+str(item)+" ing,index="+str(index))
   item.send(message1)
   item.send(message2)
   item.send(message3)

  t = Timer(86400,sendNews)
  t.start()
 except:
  errorMessage = "xxx"
  for index,item in enumerate(friend):
   item.send(errorMessage)


if __name__ == "__main__":
 sendNews()

以上即为本文分享的全部内容,希望能为读者的学习提供一定帮助,同时也欢迎大家继续支持本站获取更多技术资源。

相关标签:

本站声明

本文内容仅供参考,不代表本站观点。转载或引用请注明出处。如发现内容问题,请通过联系我们页面反馈。

Python 相关产品和应用

全部下载

专题列表