公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

Python有很多有趣的库,其中wxpy是连接微信的接口,

具体可以查看官方文档:http://wxpy.readthedocs.io/zh/latest/index.html。

可以实现自动操作,wxpy 支持 Python 3.4-3.6,以及 2.7 版本。

python实现给微信指定好友定时发消息

 

 

一、安装

win10环境,直接在cmd中,输入

pip install wxpy

有时网络不稳定,可能出现错误,重新执行操作尝试一下。

二、简单介绍

# 导入模块

from wxpy import *

# 初始化机器人,扫码登陆

bot = Bot()

# 搜索名称含有 "游否" 的男性深圳好友

my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]

三、详细代码

打开cmd,执行jupyter notebook,打开ipython环境,在打开的浏览器页面中,新建一个python3的ipynb文件。

from __future__ import unicode_literals

from threading import Timer

from wxpy import *

import requests

 

bot = None

def get_news():

#获取一个连接中的内容

url = "http://open.iciba.com/dsapi/"

r = requests.get(url)

print(r.json())

contents = r.json()['content']

translation = r.json()['translation']

return contents,translation

def login_wechat():

global bot

bot = Bot()

# bot = Bot(console_qr=2,cache_path="botoo.pkl")#linux环境上使用

def send_news():

if bot == None:

login_wechat()

try:

my_friend = bot.friends().search(u'xxx')[0] #xxx表示微信昵称

my_friend.send(get_news()[0])

my_friend.send(get_news()[1][5:])

my_friend.send(u"咦?我是自动人!!")

t = Timer(360, send_news) #360是秒数

t.start()

except:

print(u"失败!!")

if __name__ == "__main__":

send_news()

print(get_news()[0])

然后按ctrl+enter键执行。

python实现给微信指定好友定时发消息

 

分享到:
标签:python
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定