我有下面的脚本,我希望它每30分钟运行一次,有人可以向我指出正确的方法.我已经搜索了类似这样的现有问题,但是似乎找不到任何适合我的脚本的想法,但是不知道这是否是我愚蠢的问题.我的脚本转到屏幕点击的不同位置,然...

我有下面的脚本,我希望它每30分钟运行一次,有人可以向我指出正确的方法.
我已经搜索了类似这样的现有问题,但是似乎找不到任何适合我的脚本的想法,但是不知道这是否是我愚蠢的问题.
我的脚本转到屏幕点击的不同位置,然后进行屏幕截图,然后将图像发送给我的gmail帐户.
import pyautogui
import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import encoders
import os
time.sleep(5)
pyautogui.PAUSE = 1
pyautogui.moveTo(922,134)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,277)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,297)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,315)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.screenshot('web.png')
pyautogui.PAUSE = 5
gmail_user = "user@gmail.com"
gmail_pwd = "password"
to = "user@gmail.com"
subject = "Report"
text = "Picture report"
attach = 'web.png'
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
解决方法:
使用Windows schtasks:
schtasks /create /sc minute /mo 30 /tn "PyAutoGUI Task" /tr "python <path to script>"
沃梦达教程
本文标题为:如何在Windows上使用python使我的脚本每30分钟重复一次


基础教程推荐
猜你喜欢
- python sys模块使用方法介绍 2022-09-03
- Python爬虫爬取属于自己的地铁线路图 2023-08-05
- Python 3.7 安装 Centos 2023-09-04
- Windows下使用python库 curses遇到错误消息的解决方案 2023-09-03
- linux 安装 python3 2023-09-03
- CentOS7.4 安装Python3.5 2023-09-03
- Python 数据分析教程探索性数据分析 2022-08-30
- ubuntu16.04中将python3设置为默认 2023-09-04
- 利用Python将txt文件录入Excel表格的全过程 2023-08-04
- 基于Python Dash库制作酷炫的可视化大屏 2023-08-04