python 每天如何定时启动爬虫任务

想要每天定时启动,最好是把程序放在linux服务器上运行,毕竟linux可以不用关机,即定时任务一直存活;

#coding:utf8
import datetime
import time
 
def doSth():
    # 把爬虫程序放在这个类里
    print(u'这个程序要开始疯狂的运转啦')

一般网站都是1:00点更新数据,所以每天凌晨一点启动

def main(h=1,m=0):
    while True:
        now = datetime.datetime.now()
        # print(now.hour, now.minute)
        if now.hour == h and now.minute == m:
            break
        # 每隔60秒检测一次
        time.sleep(60)
    doSth()

猜你喜欢

转载自blog.csdn.net/qq_43061705/article/details/83794734