dataabc / weiboSpider

新浪微博爬虫,用python爬取新浪微博数据
8.37k stars 1.98k forks source link

定时功能 #474

Closed KT197 closed 1 year ago

KT197 commented 2 years ago

请问怎样添加下方代码,实现定时功能。

def auto_spider(stop_time): schedule.every(1).minutes.do(main) while True: if datetime.datetime.now().strftime('%H:%M') <= stop_time: schedule.run_pending() time.sleep(60) else: break

if name == 'main': auto_spider('22:00')

KT197 commented 2 years ago

import time import datetime import schedule

import os import sys

from absl import app sys.path.append(os.path.abspath(os.path.dirname(os.getcwd()))) from weibo_spider.spider import main as mn

def func(): app.run(mn)

def auto_spider(stop_time): schedule.every(1).minutes.do(func) while True: if datetime.datetime.now().strftime('%H:%M') <= stop_time: schedule.run_pending() time.sleep(600) else: break

if name == 'main': auto_spider('20:00')

对原文件进行了修改,但是无法实现定时刷新,不知道是方法不对,还是代码错误了

dataabc commented 2 years ago

你可以使用第三方工具定时执行程序。

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.