爬虫 开启定时任务

1、导入模块

import datetime
import time

 

2、代码

def time_task():
    while True:
        now = datetime.datetime.now()
        # print(now.hour, now.minute)
        if now.hour == 0 and now.minute == 0:
            start_spider()
        if now.hour == 6 and now.minute == 0:
            break
        # 每隔60秒检测一次
        time.sleep(60)

 

posted @ 2020-08-05 17:49  市丸银  阅读(234)  评论(0编辑  收藏  举报