微信咨询

微信咨询

13610*910*9

服务热线 7*24小时

电话咨询

python每分钟自动截图电脑屏幕并发送截图到指定邮箱

iamdu2019-12-31 14:30:02 浏览: 156245
import requests
import smtplib
import schedule
import time
from bs4 import BeautifulSoup
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.header import Header
from PIL import ImageGrab

account = '121942198@qq.com'
password = '' #QQ邮箱授权码
receiver = '76123708@qq.com'

# def weather_spider():
#     headers={'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}
#     url='http://www.weather.com.cn/weather/101280801.shtml'
#     res=requests.get(url,headers=headers)
#     res.encoding='utf-8'
#     soup=BeautifulSoup(res.text,'html.parser')
#     tem1= soup.find(class_='tem')
#     weather1= soup.find(class_='wea')
#     tem=tem1.text
#     weather=weather1.text
#     return tem,weather

def send_email():
    mailhost='smtp.qq.com'
    qqmail = smtplib.SMTP_SSL(host='smtp.qq.com')
    qqmail.connect(mailhost,465)
    qqmail.login(account,password)

    # 以html格式构建邮件内容
    send_str = '''
    <html>
    <body>
    <center>下边是一张图片</center>
    <img src="cid:image1" alt="image1" align="center" width=100% >
    <center>上边是一张图片</center>
    </body>
    </html>
    '''

    # 构建message
    message = MIMEMultipart()
    # 添加邮件内容
    content = MIMEText(send_str, _subtype='html', _charset='utf8')
    message.attach(content)

    # 构建并添加图像对象
    img1 = MIMEImage(open('cut.jpg', 'rb').read(), _subtype='octet-stream')
    img1.add_header('Content-ID', 'image1')
    message.attach(img1)   

    # 构建并添加附件对象
    img = MIMEImage(open('cut.jpg', 'rb').read(), _subtype='octet-stream')
    img.add_header('Content-Disposition', 'attachment', filename='cut.jpg')
    message.attach(img)

    subject = '截屏'
    message['Subject'] = Header(subject, 'utf-8')
    try:
        qqmail.sendmail(account, receiver, message.as_string())
        print ('邮件发送成功')
    except:
        print ('邮件发送失败')
    qqmail.quit()

def job():
    #电脑屏幕截屏
    img = ImageGrab.grab()
    img.save("cut.jpg")
    print('开始一次任务')
    send_email()
    print('任务完成')

schedule.every(1).minutes.do(job)
while True:
    schedule.run_pending()
    time.sleep(1)

 

欢迎留下你的看法

共 0 条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注