本文實例講述了Python使用itchat模塊實現(xiàn)簡單的微信控制電腦功能。分享給大家供大家參考,具體如下:
#!/usr/bin/python #coding=UTF-8 import requests, json import itchat import os,time,datetime from PIL import ImageGrab from itchat.content import * app_dir = r''#打開一個程序,填寫exe文件的絕對路徑 imgdir = r'E:\test.jpg' def file_edit(wr_str): f1 = open(r'E:\downloadlog.txt','a') f1.write(wr_str+'\n') f1.close() def pscr():#截取屏幕,保存圖片到指定目錄 im = ImageGrab.grab() im.save(imgdir,'jpeg') @itchat.msg_register([TEXT]) def text_reply(msg): if u"開始" in msg['Content']: itchat.send(u"收到開始指令,請稍等", msg['FromUserName']) file_edit(str(datetime.datetime.now())) time.sleep(3) os.startfile(app_dir) time.sleep(5) itchat.send(u"已開始", msg['FromUserName']) elif u'進度' in msg['Content']: itchat.send(u"收到指令,請稍等", msg['FromUserName']) pscr() itchat.send(u"請接收圖片", msg['FromUserName']) itchat.send_image(imgdir.decode('utf-8'),msg['FromUserName']) else: pass itchat.auto_login() itchat.run()
發(fā)送其他消息
給自己發(fā)送消息只需要發(fā)出消息,不指定發(fā)送者,默認發(fā)給自己(登陸者)
itchat.send_msg('nice to meet you')
發(fā)送圖片,ToUser不指定時發(fā)給自己
itchat.send_image(ImageName.decode('utf-8'),ToUser) # 發(fā)送圖片
發(fā)送視頻
itchat.send_video(VideoName.decode('utf-8'),ToUser) # 發(fā)送圖片
發(fā)送文件
itchat.send_file(path.decode('utf-8')) # 圖片(文件
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python進程與線程操作技巧總結(jié)》、《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
