import time
from datetime import datetime
'''
本文件用于获取当前的日期及时间。
'''
def currentDate():
datestr = time.localtime()
# print(datestr)
# print(type(datestr))
curyear = datestr.tm_year
# print(curyear)
# print(type(curyear))
curmon = datestr.tm_mon
curday = datestr.tm_mday
curdate = str(curyear)+"-"+str(curmon)+"-"+str(curday)
# print(curdate)
return curdate
def currentTime():
timestr = datetime.now()
# print(timestr)
now = timestr.strftime('%H-%M-%S')
return now
if __name__ == '__main__':
print(currentDate())
print(currentTime())
import os
from three.mydate import currentDate,currentTime
'''
本文件用于创建目录,存放文件(截图)
'''
def createDir():
filedir = os.path.abspath(__file__)
print(filedir)
currentpath = os.path.dirname(filedir)
print(currentpath)
mydate = currentDate()
datedir = os.path.join(currentpath,mydate)
print(datedir)
if not os.path.exists(datedir):
os.mkdir(datedir)
now = currentTime()
timedir = os.path.join(datedir,now)
if not os.path.exists(timedir):
os.mkdir(timedir)
if __name__ == '__main__':
createDir()
from selenium import webdriver
from three.mydate import currentTime,currentDate
from three.myfile import createDir
driver = webdriver.Chrome()
driver.get('https://www.baidu.com/')
try:
driver.find_element_by_id('kw1').send_keys('storm')
except:
createDir()
driver.save_screenshot(".\\{}\\{}\\{}.png".format(currentDate(),currentTime(),currentTime()))
driver.quit()