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)#根据需求设定时间

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _(手动分割线)

博客小白,个人记录,很多待补充,想到再慢慢修改,欢迎批评指正。

摘自:网络上很多的大神。侵删。。

转载请附原文链接以及作者,谢谢。

一个啥都想整小白白白。。。
一个啥都想整小白白白。。。
原文地址:https://www.cnblogs.com/sky-sugar/p/14717325.html