python+selenium+new——窗口——截图——格式化日期
from selenium import webdriver
driver.get_screenshot_as_file(filename): 截取当前窗口。只会截图当前程序可见区域内的内容,浏览器框架不会截图
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
driver.save_screenshot('000.png') #此处会在当前程序目录文件夹下保存照片
driver.save_screenshot('C:\\Users\\del\\Desktop\\新建文件夹\\001.png') #会在桌面的‘新建文件夹’里保存截图,新建文件夹已经存在
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\002.png') #会在桌面的‘新建文件夹’里保存截图,新建文件夹已经存在
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("https://www.baidu.com")
time.sleep(10)
#--------------------------------------------------------------------------------
picture_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
print(picture_time) # 2020-02-15-19-18-38
#--------------------------------------------------------------------------------
picture_time2 = time.strftime("%Y-%m-%d", time.localtime(time.time()))
print(picture_time2) # 2020-02-15
#--------------------------------------------------------------------------------
picture_time3 = time.strftime("%H-%M-%S", time.localtime(time.time()))
print(picture_time3) # 2020-02-15
#--------------------------------------------------------------------------------
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\'+ picture_time +'.png') #保存于桌面已经存在的新建文件夹里:2020-02-15-19-18-38.png
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\'+ picture_time2 +'.png') #日期作为文件名
driver.get_screenshot_as_file('C:\\Users\\del\\Desktop\\新建文件夹\\'+ picture_time3 +'.png') #时分秒作为文件名
driver.quit()
执行结果:
2020-02-15-19-25-51
2020-02-15
19-25-51