找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3498|回复: 2

[求助] Python微信自动发送信息

0

主题

0

帖子

0

积分

贫民

积分
0
Randy666 发表于 2020-11-25 18:21:52 | 显示全部楼层 |阅读模式
本帖最后由 Randy666 于 2020-11-25 18:23 编辑

在网上复制了一段代码到VS STUDIO里,结果点了run以后没有反应。。不知道该怎么搞
代码如下:
'''
import itchat

enableCmdQR=True
hotReload=True
itchat.auto_login(enableCmdQR=True,hotReload=True)

to_name = itchat.search_friends(name="哆啦A梦")
print(to_name)
# # 发送文本消息
for i in range(10):
    itchat.send('测试中。。。',toUserName=to_name[0]['UserName'])
#
# # 发送表情包
file_img = 'biaoqingbao.jpg'
itchat.send_image(file_img,toUserName=to_name[0]['UserName'])

from itchat.content import *

# 判断收到的信息类型,如果收到的信息是文本,则执行下面的函数
@itchat.msg_register(TEXT)
def text_reply(msg):
    print(msg.text)
    reply_text = msg.text.replace('吗?','!')
    print(reply_text)
    return reply_text

itchat.msg_register([PICTURE,RECORDING,ATTACHMENT,VIDEO])
def download_files(msg):
     print(msg)
     msg.download(msg.fileName)

itchat.auto_login(enableCmdQR=True,hotReload=True)

# 保证程序一直在运行
itchat.run()

import os
import time
import xlrd
import itchat

itchat.auto_login(enableCmdQR=True,hotReload=True)
change_time_save = time.ctime(os.stat('aaa.xlsx').st_mtime)

while True:
    time.sleep(5)
    change_time = time.ctime(os.stat('aaa.xlsx').st_mtime)
    if change_time_save == change_time:
        pass
    else:
        change_time_save = change_time
        xlsx = xlrd.open_workbook('aaa.xlsx')
        table = xlsx.sheet_by_index(0)
        content = str(table.cell_value(0,0))
        to_name = itchat.search_friends(name='微信好友备注名')
        itchat.send(content,toUserName=to_name[0]['UserName'])
        print("发送成功!时间:" + time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
run之后变成这样了:
[Running] python -u "c:\Users\Gover\Desktop\Randy\app.py"

[Done] exited with code=0 in 0.192 seconds


回复

使用道具 举报

0

主题

2

帖子

2

积分

贫民

积分
2
siddu 发表于 2021-2-13 18:47:59 | 显示全部楼层
itchat接口依靠微信网页版,现在不行了
回复 支持 反对

使用道具 举报

0

主题

18

帖子

18

积分

贫民

积分
18
宫崎峻Miyazaki 发表于 2021-7-30 22:35:01 | 显示全部楼层
你这个代码,我用pycharm运行完以后太恐怖,不忍直视。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表