import time
import datetime
import schedule
def main():
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
def auto_spider(stop_time):
schedule.every(1).minutes.do(main)
while True:
if datetime.now().strftime('%H:%M') <= stop_time:
schedule.run_pending()
time.sleep(60)
else:
break
if name == 'main':
auto_spider(stop_time='20:00')
这段定时代码运行不了,是哪里出问题?文件夹内没有datatime文件
错误提示如下:
Traceback (most recent call last):
File "D:\Spider-t\backup\autospider.py", line 20, in
auto_spider(stop_time='20:00')
File "D:\Spider-t\backup\autospider.py", line 13, in auto_spider
if datetime.now().strftime('%H:%M') <= stop_time:
AttributeError: module 'datetime' has no attribute 'now'