自动截图并保存到指定文件夹
import time
from PIL import ImageGrab
import os
import webbrowser as web
#建png目录存放截图
absPath = os.path.abspath(’.’)
path = [x for x in os.listdir(’.’) if os.path.isdir(x)]
if ‘png’ in path:
pass
else:
pngPath = os.path.join(absPath,‘png’)
os.mkdir(pngPath)
#截屏
def Screenshot():
nowtime = time.strftime(’%Y_%m_%d_%H_%M_%S’,time.localtime(time.time()))
print(nowtime)
im = ImageGrab.grab()#截屏
im.save(r’png%s.png’ %(nowtime))#保存
url = ‘https://…’#网址
每分钟截图一张,截10张
i = 0
while i < 10:
i=i+1
web.open(url)
time.sleep(10)
Screenshot()
print("\n")
os.system(‘taskkill /F/IM chrome.exe’)
time.sleep(50) #定时60s