Python使用itchat模組實現簡單的微信控制電腦功能示例
阿新 • • 發佈:2020-01-09
本文例項講述了Python使用itchat模組實現簡單的微信控制電腦功能。分享給大家供大家參考,具體如下:
#!/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()
傳送其他訊息
給自己傳送訊息只需要發出訊息,不指定傳送者,預設發給自己(登陸者)
itchat.send_msg('nice to meet you')
傳送圖片,ToUser不指定時發給自己
itchat.send_image(ImageName.decode('utf-8'),ToUser) # 傳送圖片
傳送視訊
itchat.send_video(VideoName.decode('utf-8'),ToUser) # 傳送圖片
傳送檔案
itchat.send_file(path.decode('utf-8')) # 圖片(檔案
更多關於Python相關內容感興趣的讀者可檢視本站專題:《Python程序與執行緒操作技巧總結》、《Python Socket程式設計技巧總結》、《Python資料結構與演算法教程》、《Python函式使用技巧總結》、《Python字串操作技巧彙總》、《Python入門與進階經典教程》及《Python檔案與目錄操作技巧彙總》
希望本文所述對大家Python程式設計有所幫助。