Python selenium webdriver自动化截图

#首先将一下第一段代码粘贴到一个python file中,将该python命名为jieTu.py。然后放到Python安装目录Lib下

import time
from pathlib import Path
import datetime

# nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H_%M_%S')    #日期+时间
current_time1 = time.strftime("%Y-%m-%d", time.localtime(time.time()))      #日期
print(current_time)
wj = current_time   #定义文件名称
wjj = current_time1 #定义文件夹名称
scrpath='D:\\'+str(wjj)+'\\'  #指定的保存目录
capturename = '\\首页'+str(wj)+'.png'  #自定义命名截图
wholepath = scrpath + capturename
if Path(scrpath).is_dir():  #判断文件夹路径是否已经存在
    pass
else:
    Path(scrpath).mkdir()   #如果不存在,创建文件夹
while Path(wholepath).exists():   #判断文件是否已经存在
    wj+=current_time
    capturename = '\\'+str(wj) +'.png'
time.sleep(1)
wholepath=scrpath+capturename


你可能感兴趣的:(Python selenium webdriver自动化截图)