Python實現定時監測屏幕


實現手段:

1、對屏幕定時截圖

2、將截圖的圖片通過郵件發送到郵箱

依賴庫:pillow,time,yagmail

基礎知識:1:發送郵件

     2:截圖

     3、定時
time.sleep(時間),默認為秒。

完整實現代碼:

import yagmail
from PIL import ImageGrab
import time


username = "xxxx@qq.com"#發送郵箱
password = "xxxx"
#設定發送的賬戶,方式
yag = yagmail.SMTP(user=username, password=password, host='smtp.qq.com')
#循環,也可以用while True來代替。
for i in range(5):
im = ImageGrab.grab() # 無參數默認全屏截屏
im.save('shot.jpg') # 截圖保存,默認是當前目錄
address = "xxxxx@qq.com"#發送到xxx郵箱
# 標題
title = [
"測試郵件" + str(i+1)
]
# 內容
content = [
"屏幕現況"
, yagmail.inline("shot.jpg") # 插入圖片並顯示到正文
]
# 4、發送郵件
yag.send(to=address, subject=title, contents=content)
# 5、關閉連接
yag.close()
time.sleep(10)#根據需求設定時間

 

 

 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _(手動分割線)

博客小白,個人記錄,很多待補充,想到再慢慢修改,歡迎批評指正。

摘自:網絡上很多的大神。侵刪。。

轉載請附原文鏈接以及作者,謝謝。

一個啥都想整小白白白。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM